[ top | up ]

Value Matching

Syntax

match(x, table, nomatch=NA)

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.

Description

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.

See Also

pmatch for partial string matching.

Examples

"%in%" <- function(a, b) !is.na(match(a, b))#- following John Wallace 1:10 %in% c(1,3,5,9) sstr <- c("c","ab","B","bba","c","@","bla","a","Ba","%") sstr[sstr %in% c(letters,LETTERS)] ## The intersection of two sets : intersect <- function(x, y) y[match(x, y, nomatch = 0)] intersect(1:10,7:20)