This help topic is for R version 0.60. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/match.html
match {base}R Documentation

Value Matching

Description

match: If x[i] is found to equal table[j] then the value returned in the i-th position of the return value is j. If no match is found, the value is nomatch.

%in%: A utility function, currently defined as
"%in%" <- function(x, y) match(x, y, nomatch = 0) > 0 allowing an intuitive usage and returning a logical vector of length length(x).

Usage

match(x, table, nomatch=NA)
x %in% table

Arguments

x

the values to be matched.

table

the values to be matched against.

nomatch

the value to be returned in the case when no match is found.

See Also

pmatch for partial string matching.

Examples

## The intersection of two sets :
intersect <- function(x, y) y[match(x, y, nomatch = 0)]
intersect(1:10,7:20)

1:10 %in% c(1,3,5,9)
sstr <- c("c","ab","B","bba","c","@","bla","a","Ba","%")
sstr[sstr %in% c(letters,LETTERS)]

[Package base version 0.60 ]