我需要选择一个数据框的所有行,在其中一列中可以找到值“ x”。
如果列数很小,我可以这样做:
dat1=data.frame(vec1=c("x","a","b","b","b","a","x","b","b","a"),
vec2=c("a","a","b","a","b","a","a","b","b","a"),
vec3=c("x","b","b","b","b","a","b","b","b","b"),
value=c(1,2,42,3,7,30,31,32,4,14))
dat2=dat1[which(dat1$vec1=="x" | dat1$vec2=="x" | dat1$vec3=="x"),]
问题是我有很多列(从vec1到vec40)。有没有一种快速的方法来选择我想要的所有行?
谢谢您的帮助!