Let's say I have three vectors, and I want to compare them to see elements of each are NOT in the others, starting by comparing to "c."
a<-c(1,2,7,8)
b<-c(1,2,3,4)
c<-c(3,4,5,6)
So this works like I expect it to (1 and 2 are in "b" but not "c.")
b[-which(b%in%c)]
returns:
[1] 1 2
But this doesn't tell me which of "a" is not in "c" (all of it, i.e. 1,2,7,8), rather it gives me a numeric vector with nothing in it.
a[-which(a%in%c)]
returns:
integer(0)
It looks like this answer would do what I want in the end, but what am I misunderstanding about how my use of which
and %in%
works? Better yet, how do I get the answer
[1] 1 2 7 8
from the question of which of "a" is not in "c" when none of "a" is in "c?"