“Not in” in R

When processing data it is common to test if an observation belongs to a set. Let’s suppose that we want to see if the sample code belongs to a set that includes A, B, C and D. In R it is easy to write something like:

Now, what happens if what we want are the observations that are not in that set? Simple, we use the negation operator (!) as in:

In summary, surround the condition by !().

Leave a comment

Your email address will not be published.