charmatch
Partial Matching of Character Strings
Description
Returns a vector of the indices of table that are partially matched by
x.
Usage
charmatch(x, table, nomatch = NA_integer_)
Arguments
x |
character vector of items to be matched sequentially in table,
using the partial match algorithm.
|
table |
character vector giving the possible values in x.
|
nomatch |
the value to be returned when an item in x does not partially
match any item in table.
|
Details
This function is useful for processing the arguments to functions.
It is similar to the pmatch function.
However, pmatch does not allow a distinction between no match and
an ambiguous match.
The pmatch function does not allow a match to an empty string, but
charmatch does.
Value
an integer vector like input containing the index of table that
partially matches x.
If none of the elements of table match, nomatch is returned.
If the match is ambiguous, 0 is returned.
See Also
Examples
charmatch("mea", c("mean", "median", "mode")) # returns 1
charmatch("m", c("mean", "median", "mode")) # returns 0
pmatch("m", c("mean", "median", "mode")) # returns NA
charmatch(c("sin", "cot"), c("cos", "sin", "tan"), nomatch = -1)
# returns c(2, -1)
charmatch("","") # returns 1
pmatch("","") # returns NA