Match Items in Vector - Generic function

DESCRIPTION:
Returns a vector of the positions in table of the elements of x.

This function is generic (see Methods); method functions can be written to handle specific classes of data. Classes which already have methods for this function include: factor.


USAGE:
match(x, table, nomatch=NA, incomparables=F)

REQUIRED ARGUMENTS:
x:
vector of items that are to be looked for in table. Missing values and and Infs are allowed.
table:
the possible values in x. Missing values and Infs are allowed.

OPTIONAL ARGUMENTS:
nomatch:
the value to be returned when an item in x does not match any item in table. A useful alternative to NA is nomatch=0, which has the effect that unmatched items are ignored when the matched indices are used in subscripts (see the last example below).
incomparables:
a vector of values that cannot be matched, any value in x that matches a value in this vector is assigned the nomatch value. If incomparables is FALSE all values can be matched.

VALUE:
integer vector of the same length as x giving, for each element of x, the smallest i such that table[i] equals that element. If no value in table is equal to x[j], then the jth element of the result is nomatch.

DETAILS:
Comparisons are done in the simplest mode that does not imply an information loss. For example, if both x and table are numeric, then comparisons are numeric, but if either one is a character string, then comparisons are of character strings.

SEE ALSO:
grep , amatch , charmatch .

EXAMPLES:
match(data, primes)
match(data, primes, incomp=2) # match to all primes but 2
state.abb[match(names, state.name)] #change names to abbrevs
names[match(allnames, names, 0)] #those names also found in allnames