Rev 15168 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{pmatch}\title{Partial String Matching}\usage{pmatch(x, table, nomatch = NA, duplicates.ok = FALSE)}\alias{pmatch}\arguments{\item{x}{the values to be matched.}\item{table}{the values to be matched against.}\item{nomatch}{the value returned at non-matching or multiplypartially matching positions.}\item{duplicates.ok}{should elements be in \code{table} be used morethan once?}}\description{\code{pmatch} seeks matches for the elements of its first argumentamong those of its second.}\details{The behaviour differs by the value of \code{duplicates.ok}. Considerfirst the case if this is true. First exact matches are considered,and the positions of the first exact matches are recorded. Then uniquepartial matches are considered, and if found recorded. (A partialmatch occurs if the whole of the element of \code{x} matches thebeginning of the element of \code{table}.) Finally,all remaining elements of \code{x} are regarded as unmatched.In addition, an empty string can match nothing, not even an exactmatch to an empty string. This is the appropriate behaviour forpartial matching of character indices, for example.If \code{duplicates.ok} is \code{FALSE}, values of \code{table} oncematched are excluded from the search for subsequent matches. Thisbehaviour is equivalent to the \R algorithm for argumentmatching, except for the consideration of empty strings (which inargument matching are matched after exact and partial matching to anyremaining arguments).\code{\link{charmatch}} is similar to \code{pmatch} with\code{duplicates.ok} true, the differences being that itdifferentiates between no match and an ambiguous partial match, itdoes match empty strings, and it does not allow multiple exact matches.}\value{A numeric vector of integers (including \code{NA} if \code{nomatch =NA}) of the same length as \code{x}, giving the indices of theelements in \code{table} which matched, or \code{nomatch}.}\note{Versions of \R prior to 1.0.0 had a different behaviour that wasseriously incompatible with S (and the current version) when\code{duplicates.ok = TRUE}.}\author{Of this version, B. D. Ripley.}\seealso{\code{\link{match}}, \code{\link{charmatch}} and\code{\link{match.arg}}, \code{\link{match.fun}},\code{\link{match.call}}, for function argument matching etc.,\code{\link{grep}} etc for more general (regexp) matching of strings.}\examples{pmatch("", "") # returns NApmatch("m", c("mean", "median", "mode")) # returns NApmatch("med", c("mean", "median", "mode")) # returns 2pmatch(c("", "ab", "ab"), c("abc", "ab"), dup=FALSE)pmatch(c("", "ab", "ab"), c("abc", "ab"), dup=TRUE)## comparecharmatch(c("", "ab", "ab"), c("abc", "ab"))}\keyword{character}