使用dplyr对参数应用否定索引

时间:2016-11-20 15:38:14

标签: r dplyr plyr

test <- data.frame(A = c(1,2,3,1,0), B = c(1,1,5,6,2))

我想删除A = 1和B = 1

的观察

例如:

test <- test[-which(test$A == 1 & test$B == 1),]

如何在dplyr中完成?

 test <- filter(test, -(test$A == 1 & test$B == 1))

Error in eval(substitute(expr), envir, enclos) : 
filter condition does not evaluate to a logical vector.

1 个答案:

答案 0 :(得分:0)

filter(test, !(A == 1 & B == 1)) 

filter(test, (A != 1 | B != 1))

slice(test, -which(test$A == 1 & test$B == 1))