0

I try to do this in R:(for example) let x = c(1,2,3,4,5,6,7,8) and y=c(1,2,8)

So

x[x!=y] = numeric(0) ????

I want to get as a result 3,4,5,6,7

Is there a practical way to do this? Thanks

albert
  • 305
  • 4
  • 12

1 Answers1

1

Use value matching %in% and remove the elements of x that are present in y

x[-which(x %in% y)]
#[1] 3 4 5 6 7
d.b
  • 32,245
  • 6
  • 36
  • 77
  • This works fine, but only if there is at least one value. This wont return the whole `x` if `y` is null or empty or `c(99,98,97)`, which would somehow be expected. – Dan Chaltiel Aug 08 '17 at 13:09