Reputation: 11
x <- c("a", "b", "c", "d", "e", "f", "g")
y <- c("a", "c", "d", "z")
I am trying to compare y to x and find an index where in y that does not match with anything in x. in this case z does match and I want R to return the index of z.
This is one of the things I tried and it does not work.
index <- which(y != x)
Upvotes: 0
Views: 41
Reputation: 389135
You can also use match
which will return NA
if there is no match.
which(is.na(match(y, x)))
#[1] 4
Or another variation with setdiff
which(y %in% setdiff(y, x))
Upvotes: 1