+4 votes
in Programming Languages by (71.8k points)
Which function should I use to find the set difference between two R vectors?

1 Answer

+3 votes
by (348k points)
selected by
 
Best answer

You can use the setdiff() function to find the set difference between R vectors.

setdiff(x,y): Set difference between x and y, consisting of all elements of x that are not in y.

Here is an example:

x <- c(10,20,30,40,50,60)
y <- c(10,200,300,40,500,60)
setdiff(x,y)

The output of the above code will be:

> setdiff(x,y)
[1] 20 30 50


...