문제

I've done quite a bit of reading on this but I've not been able to get an answer that works yet.

I've been using the setdiff function in R to look at the number of matches between two dataframes. I know that I have 71 out of 200 observations matching and the remainder non-matching.

So far I've just done this to get the number of matching and non-matching values:

check = setdiff(dataset1$variable1, dataset2$variable1)

How do I return a list of the matching and non-matching values?

Thanks,

Ed

도움이 되었습니까?

해결책

All the matching values are found with the intersect function, from the Set Operations. All the values in both variables are found with the union function. So the values that are in the union, but not in the intersect are non-matching.

var1 <- LETTERS[1:5]
var2 <- LETTERS[4:8]
matched <- intersect(var1, var2)
all <-  union(var1, var2)
non.matched <- all[!all %in% matched]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top