Julia equivalent to 'not in' in R

What would be Julia code for the following R code:
a ← c(1:5)
b ← c(1:10)
c ← b[-a]



I’m not an R expert, but you want the elements of b which are NOT part of a as well, right?

One way would be:

c = Iterators.filter(x -> x ∉ a, b) (on lastest master, if you’re on 0.5 it would be c = filter(x -> x ∉ a, b)).

Do you want setdiff(b, a) ?

I frequently use b[setdiff(1:end, a)].


Oh, has filter() left Base? Must remember that…

As far as I understand, no. But it has moved into a module called Iterators within Base.

1 Like

NamedArrays implements a Not method that does what the minus index does in R. I don’t know why a very common ideom like that is not in Julia Base though?

I made a PR for something like that in Base a long while back. Seems like a reasonable addition to me.


It’s funny to see that the branch is apparently still alive.

Thanks for your replies. setdiff() seems to be a work around, but that function is the same as %in% in R.