내가 큰 데이터 세트가 있지만 여기에 내가 동일한 데이터 논쟁 문제dplyr | group_by 대 anti_join | 가장 효율적인 방법
데이터가 샘플 데이터를 생성하고하는 것은
brand=c('MS', 'Google', 'Apple', 'MS', 'FB', 'Apple', 'Oracle')
product=c('Window', 'Search', 'Iphone', 'Window', 'Network', 'Iphone', 'DB')
isExist=c('Yes', 'Yes', NA, 'No', NA, 'Yes', NA)
df= data.frame(brand, product, isExist)
이 데이터는 지금이
brand product isExist
1 MS Window Yes
2 Google Search Yes
3 Apple Iphone <NA>
4 MS Window No
5 FB Network <NA>
6 Apple Iphone Yes
7 Oracle DB <NA>
처럼 나는 isExist에 대한 NA 항목이없고 값이있는 동일한 복합 키에 대해 다른 행을 가지고 있지 않은 브랜드 및 제품 (복합 키)을 기반으로하는 행을 원합니다. 즉 FB, Oracle를 반환해야하지만 Apple은 행 중 하나가 아닙니다. ro 더 6) isExist 가치가 없다 승
I, 여기에 코드 anti_join을 사용하여 달성하고
library(dplyr)
testWithData <- df %>% filter(!is.na(isExist))
testWithoutData <- df %>% filter(is.na(isExist))
final <- unique(anti_join(testWithoutData, testWithData, by = c('brand', 'product')))
출력
brand product isExist
1 FB Network <NA>
2 Oracle DB <NA>
이 솔루션은
을하고있다하지만 나는 알고있다, 너무 많은 시간이 소요 가장 효율적인 방법은 아닙니다. 나는 GROUP_BY 및 필터가 마법을 할 수 있다고 생각하지만, 나는 누군가가 먼저 (단계로이 단계를 실행하면 위의 과정을 이해할 수
2 행, 먼저 3 등) NA의 (예 : 1). 내 질문에 대한 최상위 답변보기 : https://stackoverflow.com/questions/47289543/modify-certain-values-in-a-data-frame-by-indirect-reference-to-the-columns/47310247?noredirect= 1 # comment81573872_47310247 – Stanwood