grapes-nin-grapes: A shortcut for negation of the %in% operator.

Description Usage Arguments Value Examples

Description

Using a negation of %in% operator in the standard format produces less readable code. More natural way of using negation in this context would be to prepend 'in' with standard negation symbol, '!', which then results in using shorter and more readable 'x %!in% y' instead of '!(x %in% y)'. However, since R does not allow using '!' in function names, we use a special keyword 'nin' instead of '!in'.

Usage

1
x %nin% y

Arguments

x

A data structure whose elements will be checked whether they are also present in data structure y.

y

A data structure that will be checked whether elements from x are present in it.

Value

A logical vector of equal length as x, with element(s) not being present in y as TRUE. If x was a matrix, then the output corresponds to x converted to a vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# create some numeric vectors
x <- 1:4
y <- 3:6

# standard form
results <- !(x %in% y)

# new abbreviated format
resultsNew <- x %nin% y
all(results == resultsNew)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.