[英]Select rows where at least the condition is present in 2 columns in R
[英]R - Select rows where at least X columns matches condition
我试图选择那些至少有4列具有相同值的行。 到目前为止,我已经尝试了apply函数,我可以得到任何行或每行匹配的行。
team.composition[apply(team.composition, 1, function(X) any(as.numeric(X) == 1)),]
这是我的表的一个例子
member.1 member.2 member.3 member.4 member.5
1 3 8 5 3
2 3 2 2 2
7 4 8 8 3
1 8 8 8 8
我想要的是返回第二行(2,3,2,2,2)和第四行(1,8,8,8,8)。
有什么建议? 谢谢
尝试
df1[apply(df1, 1,function(x) any(table(x)>=4)),]
要么
library(reshape2)
df1[!!rowSums(table(melt(as.matrix(df1))[-2])>=4),]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.