match()
and %in%
match()
returns the indices of elements inx
that have matching values intable
table <- sample(c(1:10, NA), size = 100, replace = TRUE)
x <- c(5, 6, NA)
# returns indices in table
match(x, table, nomatch = 0)
## [1] 24 23 7
%in%
is an intuitive wrapper that returns a logical vector instead
## [1] TRUE TRUE TRUE