Partial Matching of Character Items in a Vector

DESCRIPTION:

Returns, for each element of x, the position in table or unique completion whose initial substring matches that element.

USAGE:

pmatch(x, table, nomatch=NA, duplicates.ok=F) 

REQUIRED ARGUMENTS:

x
character vector or bdCharacter of items to be matched sequentially in table, using the partial match algorithm.
table
character vector or bdCharacter giving the possible values in x.

OPTIONAL ARGUMENTS:

nomatch
the value to be returned when an item in x does not uniquely match any item in table.
duplicates.ok
logical flag; indicates whether to allow duplicate values.
If FALSE, duplicate values in x correspond to nomatch; this is the way to simulate function call name matching.
If the goal is to simulate character subset calculations, however, this argument should be TRUE.

VALUE:

numeric vector or bdNumeric like x giving, for each element of x, the position in table of the first table[i] whose initial substring uniquely matches that element.

DETAILS:

Matching is done by the same algorithm used to match named arguments in S-PLUS function calls; see Section 11.3.5 of Becker, Chambers and Wilks. However, pmatch does not match empty strings, in contrast to the argument-matching algorithm, which matches unnamed arguments positionally after dealing with named arguments.

The charmatch function is a close synonym of pmatch. See the documentation for charmatch for a comparison of their differences.

SEE ALSO:

, , , .

EXAMPLES:

pmatch("Ala",state.name) # is NA (could match Alaska or Alabama) 
pmatch("Alab",state.name) # is 1, matching Alabama 
# given names, possibly truncated versions of state names 
# produce the full state names 
state.name[pmatch(names,state.name)]