grapes-ni-grapes: The "Not In" function

%ni%R Documentation

The "Not In" function

Description

This returns TRUE if values are not in a list. It's the opposite of %in%. This is particularly good when subsetting and you only want to remove a few things (like diphthongs). You can remove those rather than specifying all monophthongs you want to keep.

Usage

x %ni% y

Arguments

x

A vector, presumably a subset of "y"

y

A vector

Details

Note that what this function does can easily be accomplished with !x %in% y, but I like the "not in" aspect. Probably a holdover from my Perl days...

You can also define this function as `%ni%` <- Negate(`%in%`) but when looking through the documentation on %in%, I found that it might be better to modify the formal definition there instead.

Credit to this Stack Overflow question for showing how to get this to work in an R package.

Value

A list of logicals indicating whether the objects in x are not contained in y.

Examples

1:10 %in% c(1,3,5,9)
1:10 %ni% c(1,3,5,9)

JoeyStanley/joeyr documentation built on April 7, 2023, 8:37 p.m.