我有以下数据框:
ID Degree1 Degree2 Degree3 Degree4 Degree6 Degree6
1001 10 5 0 6 4 12
1002 0 0 0 0 0 0
1003 0 2 0 0 9 0
我想要在所有 6 度中仅包含值 0 的行。我检查了以下命令但没有起作用:
subset(data, data$Degree1:Degree6 == 0)
有人可以帮我解决这个问题吗?
最佳答案
我们可以使用rowSums
data[rowSums(data[-1]==0)==6,]
或者使用否定!
data[!rowSums(data[-1]!=0),]
关于r - 基于 R 中列集中的值的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42632218/