pmatch seeks matches for the elements of its first argument
among those of its second.
the values to be matched: converted to a character vector by
the values to be matched against: converted to a character vector. Long vectors are not supported.
the value to be returned at non-matching or multiply
partially matching positions. Note that it is coerced to
should elements be in
The behaviour differs by the value of
first the case if this is true. First exact matches are considered,
and the positions of the first exact matches are recorded. Then unique
partial matches are considered, and if found recorded. (A partial
match occurs if the whole of the element of
x matches the
beginning of the element of
all remaining elements of
x are regarded as unmatched.
In addition, an empty string can match nothing, not even an exact
match to an empty string. This is the appropriate behaviour for
partial matching of character indices, for example.
FALSE, values of
matched are excluded from the search for subsequent matches. This
behaviour is equivalent to the R algorithm for argument
matching, except for the consideration of empty strings (which in
argument matching are matched after exact and partial matching to any
charmatch is similar to
duplicates.ok true, the differences being that it
differentiates between no match and an ambiguous partial match, it
does match empty strings, and it does not allow multiple exact matches.
NA values are treated as if they were the string constant
An integer vector (possibly including
NA) of the same length as
x, giving the indices of the
table which matched, or
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Chambers, J. M. (1998) Programming with Data. A Guide to the S Language. Springer.
match.call, for function argument matching etc.,
startsWith for particular checking of initial matches;
grep etc for more general (regexp) matching of strings.
1 2 3 4 5 6 7 8
pmatch("", "") # returns NA pmatch("m", c("mean", "median", "mode")) # returns NA pmatch("med", c("mean", "median", "mode")) # returns 2 pmatch(c("", "ab", "ab"), c("abc", "ab"), dup = FALSE) pmatch(c("", "ab", "ab"), c("abc", "ab"), dup = TRUE) ## compare charmatch(c("", "ab", "ab"), c("abc", "ab"))