nin: Find Non-Matching Elements

%nin%R Documentation

Find Non-Matching Elements

Description

%nin% finds non-matching elements in a given vector. It is the negation of %in%.

Usage

a %nin% b

Arguments

a

a vector (character, factor, or numeric)

b

a vector (character, factor, or numeric)

Details

This is a simple negation of %in%. I use it mostly for columns in a data frame.

Value

%nin% finds non-matching elements and returns one of two things, depending on the use. For two simple vectors, it will report what matches and what does not. For comparing a vector within a data frame, it has the effect of reporting the rows in the data frame that do not match the supplied (second) vector.

Examples


library(tibble)
library(dplyr)

# Watch this subset stuff

dat <- tibble(x = seq(1:10), d = rnorm(10))
filter(dat, x %nin% c(3, 6, 9))


stevemisc documentation built on Sept. 11, 2024, 5:23 p.m.