Extracting value specific rows in R

Assuming that your data is in a data frame called mydata, you can select the rows you want by writing

  mydata[mydata$A_Pval<0.05 & mydata$B_Pval<0.05 & mydata$C_Pval<0.05,]

It might be easier to understand by doing it in multiple steps:

# gives a logical vector telling you if A_Pval is smaller than 0.05
significant_A <- mydata$A_Pval<0.05 

# gives a logical vector telling you if B_Pval is smaller than 0.05
significant_B <- mydata$B_Pval<0.05 

# gives a logical vector telling you if C_Pval is smaller than 0.05
significant_C <- mydata$C_Pval<0.05 

# combine the results to one logical vector
# significant_all[i] has value TRUE if all the p-values in row i 
# are smaller than 0.05

significant_all <- significant_A & significant_B & significant_C

# pick the rows you want
mydata[significant_all,]

Leave a Comment

tech