Which numbers are present in a vector but not in another one

any, r

Solution

setdiff(v1, v2)
# [1]  1  3  5  6  8  9 10

Problem

I guess it is a very easy question. ``` v1 = 1:10 v2 = c(2,4,7) ``` (none of the numbers are repeated. No need to use `unique()`) I want a vector containing all the values in v1 that are not in v2. ``` solution = c(1,3,5,6,8,9,10) ``` I can do this using a for loop but I'm sure there are easier solution.

Original source

Related problems