2016-12-07 5 views
-2

두 개의 데이터 프레임이 있습니다.두 번째 데이터 프레임으로 데이터 프레임 필터링

selectedcustomersa은 50 명의 고객에 대한 정보가 포함 된 데이터 프레임입니다. 주먹 열은 이름입니다 (Group.1).

selectedcustomersb은 2000 년 고객에 대한 정보가있는 다른 데이터 프레임 (동일한 구조)과 selectedcustomersa의 고객이 포함되어 있습니다.

고객이 없으면 selctedcustomersa이 필요하지 않습니다.

내가 시도 :

newselectedcustomersb<-filter(selectedcustomersb, Group.1!=selectedcustomersa$Group.1) 
+0

'setdiff'를 사용할 수 있습니다. 'newselectedcustomersb <- selectedcustomersb [selectcustomersb $ Group1 % in setdiff (selectedcustomersb $ Group.1, selectedcustomersa $ Group.1)]와 같은 것입니다. – lmo

답변

2

보십시오 :이 작업을 수행하는

newselectedcustomersb <- filter(selectedcustomersb, !(Group.1 %in% selectedcustomersa$Group.1)) 
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 
관련 문제