I have two character vectors, x and y.
x <- c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\") y <- c(\"a\", \"c\", \"d\", \"e\", \"g\") <
x <- c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\") y <- c(\"a\", \"c\", \"d\", \"e\", \"g\")
I think this should work:
x[!(x %in% y)]
First it checks for all x that are not in y, then it uses that as an index on the original.
setdiff(x,y)
Will do the job for you.
> x[!x %in% y] [1] "b" "f"
or:
> x[-match(y,x)] [1] "b" "f" >