我有两个数据帧。
selectedcustomersa
是一个包含50个客户信息的数据框。 Fist列是名称(Group.1)。
selectedcustomersb
是另一个数据框(相同结构),其中包含有关2000个客户的信息,其中包含来自selectedcustomersa
的客户。
我希望selctedcustomersb
没有来自selctedcustomersa
的客户。
我试过了:
newselectedcustomersb<-filter(selectedcustomersb, Group.1!=selectedcustomersa$Group.1)
答案 0 :(得分:3)
执行此操作的一种方法是在dplyr中使用anti_join
,如下所示。它可以跨多个列等工作。
library(dplyr)
df1 <- data.frame(x = c('a', 'b', 'c', 'd'), y = 1:4)
df2 <- data.frame(x = c('c', 'd', 'e', 'f'), z = 1:4)
df <- anti_join(df2, df1)
df
x z
1 e 3
2 f 4
答案 1 :(得分:2)
尝试:
newselectedcustomersb <- filter(selectedcustomersb, !(Group.1 %in% selectedcustomersa$Group.1))