Partial Matching of Character Strings

DESCRIPTION:

Returns a vector of the indices of target that are partially matched by input .

USAGE:

charmatch(input, target, nomatch=NA) 

REQUIRED ARGUMENTS:

input
vector of character strings to match.
target
vector of target character strings to match against.

OPTIONAL ARGUMENTS:

nomatch
the value to be returned when a string in input does not partially match any string in target.

VALUE:

an integer vector like input containing the index of target that partially matches input. If none of the elements of target match, nomatch is returned. If it is an ambiguous match, a 0 is returned.

DETAILS:

This function is useful for processing the arguments to functions. It is very 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 the empty string, while charmatch does.

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