I have 3 vectors
x <- c(1,3,5,7,3,8) y <- c(3,5,7) z <- c(3,3,8)
I want to find the elements of x that are not in
x
match with a little for-loop does work:
match
> f(x, y) [1] 1 3 8 > f(x, z) [1] 1 5 7
f <- function(s, r) { for(i in 1:length(s)){ j <- match(s[i], r) if(!is.na(j)) { s[i] <- NA r[j] <- NA } } print(s[complete.cases(s)]) }