2012-03-16 61 views
2

我有一个带有多个列的制表符分隔文件。我只想要那些pvalue为< .05的行。提取R中的值特定行

Probe A_sig A_Pval B_sig B_Pval C_sig C_Pval D_sig D_Pval 
ILMN_122 12.31 0.04 23.6 0.4  124.5 0.04  567.4 0.008 
ILMN_456 56.12 0  23.89 0.55 567.2 0.214 56.35 0.01 
ILMN_198 981.2 0.06 31.56 0.02 12.56 0.4  789.4 0.045 
ILMN_980 876.0 0.001 124.7 0.01 167.3 0.12  245.7 0.35 
ILMN_542 123.9 0.16 219.8 0.04 567.3 0.03  987.6 0.34 
ILMN_567 134.1 0  542.5 0.24 12.56 0.65  5.67  0.56 
ILMN_452 213.4 0.98 12.6 0.12 17.89 0.03  467.8 0.003 
ILMN_142 543.8 0.04 245.6 0.89 456.34 0.001 12.67 0.002 
ILMN_765 187.4 0.05 34.6 0.001 67.8  0.06  78.34 0.02 

我需要的输出如下:

 Probe A_sig A_Pval B_sig  B_Pval C_sig C_Pval 
    ILMN_122 12.31 0.04 32.56  0.004 311.4 0.001 
    ILMN_980 876.0 0.001 123.4  0.001 678.9 0.02 
    ILMN_142 543.8 0.04 56.56  0.015 67.8 0.04 
+0

只是几个小时前的相关问题:http://stackoverflow.com/questions/9729962/extracting-rows-based-on-the-value-in-r – Ben 2012-03-16 15:27:04

+1

@Ben Thileepan也提出了这个问题。最初的问题得到了回答,我要求海报问一个新的问题,因为原文已经回答了。 – 2012-03-16 15:36:19

+0

你说得对,我应该仔细看看。现在,当下一个人需要知道如何进行这些方便的子设置(即我,下周...)时,他们正式联系在一起。我经常发现“链接”的问题是有用的和有趣的。 – Ben 2012-03-16 17:29:57

回答

10

假设你的数据在一个名为MYDATA数据帧时,您可以通过编写

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

选择您想要的行它可能更容易通过多步操作来理解:

# 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,]