# (R) How can I get the complement of vector y in vector x

Posted
by gd047
on Stack Overflow
See other posts from Stack Overflow
or by gd047

Published on 2010-03-21T17:11:15Z
Indexed on
2010/03/21
17:11 UTC

Read the original article
Hit count: 365

That's `x \ y`

using mathematical notation. Suppose

```
x <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,1,1,1,3)
y <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1)
```

How can I get a vector with ALL the values in x that are not in y. i.e the result should be:

```
2,1,1,3
```

There is a similar question here. However, none of the answers returns the result that I want.

© Stack Overflow or respective owner