簡體   English   中英

R:如果存在值,則搜索多列保留該行

[英]R: Search through multiple columns if value is present keep that row

如果搜索第二列,並且在一行中,一列的值大於 0.95,那么我想要做什么,然后保留它。 基本上,保留的行必須至少有一列 >0.95。 示例 df:

     Id VALUE_Sample1 DetectionScore_Sample1 VALUE_Sample2 DetectionScore_Sample2
1 10265        -0.251                 0.8874       -0.1850                 0.2120
2 10265         0.560                 0.9989        0.6610                 0.9456
3 12346         0.874                 1.0000        0.7545                 0.9900 

因此,我想查看“DecetionScore_”列並查找大於 0.95 的任何值,以便返回上述內容。

     Id VALUE_Sample1 DetectionScore_Sample1 VALUE_Sample2 DetectionScore_Sample2
1 10265         0.560                 0.9989        0.6610                 0.9456
2 12346         0.874                 1.0000        0.7545                 0.9900 

我嘗試的代碼是

newdf<-df[df[,(seq(3,151,2)] >= 0.95,]  ## col 1 is IDs

有什么想法可以解決這個問題嗎?

df2 = df[which(apply(df[,seq(3,151,2)], 1, max) > 0.95),]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM