pmatch(x, table, nomatch = NA_integer_, duplicates.ok = FALSE)
x | a character vector of items to match sequentially in table, using the partial match algorithm. |
table | a character vector giving the possible values in x. |
nomatch | the value to return when an item in x does not uniquely match any item in table. |
duplicates.ok |
a logical value. If set to FALSE (the default), duplicate values in x correspond
to nomatch. You can use this technique to simulate function call name matching.
If set to TRUE, matches duplicate values. You can use this technique to simulate character subset calculations. |
pmatch("Ala", Sdatasets::state.name) # is NA (could match Alaska or Alabama) pmatch("Alab", Sdatasets::state.name) # is 1, matching Alabama# Given names, possibly truncated versions of state names # produce the full state names and skip the ones that don't match # by setting nomatch to zero. names <- c('Flo', 'Zzz', 'Mon') Sdatasets::state.name[pmatch(names, Sdatasets::state.name, nomatch=0)]