french_fries
french_fries

Reputation: 1

Filter vector by vector

I have vectors:

a <- c(1,2,4,5,6)
b <- c(2,4,5)

A want to extract values from 'a' which are not in 'b', so desired output is:

1,6

How could i do that?

Upvotes: 0

Views: 56

Answers (1)

akrun
akrun

Reputation: 887951

We can use setdiff

setdiff(a, b)
#[1] 1 6

Or if there are duplicates

library(vecsets)
vsetdiff(a, b)

Or using %in% and !

a[! a %in% b]

Upvotes: 2

Related Questions