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

1 Answer

+2 votes
by (48.9k points)

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


...