pmatchseeks matches for the elements of its first argument among those of its second.
pmatch(x, table, nomatch = NA_integer_, duplicates.ok = FALSE)
tablebe used more than once?
nomatch = NA) of the same length as
x, giving the indices of the elements in
tablewhich matched, or
duplicates.ok. Consider 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
xmatches the beginning of the element of
table.) Finally, all remaining elements of
xare 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
Chambers, J. M. (1998) Programming with Data. A Guide to the S Language. Springer.
match.call, for function argument matching etc.,
startsWithfor particular checking of initial matches;
grepetc for more general (regexp) matching of strings.
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"))
Run the code above in your browser using DataCamp Workspace