In R, how do you test for elements of one vector NOT present in another vector?
X <- c(\'a\',\'b\',\'c\',\'d\')
Y <- c(\'b\', \'e\', \'a\',\'d\',\'c\',\'f\
A warning about setdiff
: if your input vectors have repeated elements, setdiff
will ignore the duplicates. This may or may not be what you want to do.
I wrote a package vecsets
, and here's the difference in what you'll get. Note that I modified X
to demonstrate the behavior.
library(vecsets)
X <- c('a','b','c','d','d')
Y <- c('b', 'e', 'a','d','c','f', 'c')
setdiff(X,Y)
character(0)
vsetdiff(X,Y)
[1] "d"