match() and %in%

  • match() returns the indices of elements in x that have matching values in table
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
# returns logical in x
x %in% table
## [1] TRUE TRUE TRUE