Rev 38292 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{agrep}\alias{agrep}\alias{fuzzy matching}\title{Approximate String Matching (Fuzzy Matching)}\description{Searches for approximate matches to \code{pattern} (the first argument)within the string \code{x} (the second argument) using the Levenshteinedit distance.}\usage{agrep(pattern, x, ignore.case = FALSE, value = FALSE,max.distance = 0.1)}\arguments{\item{pattern}{a non-empty character string to be matched (\emph{not}a regular expression!). Coerced by \code{as.character} to a stringif possible.}\item{x}{character vector where matches are sought. Coerced by\code{as.character} to a character vector if possible.}\item{ignore.case}{if \code{FALSE}, the pattern matching is \emph{casesensitive} and if \code{TRUE}, case is ignored during matching.}\item{value}{if \code{FALSE}, a vector containing the (integer)indices of the matches determined is returned and if \code{TRUE}, avector containing the matching elements themselves is returned.}\item{max.distance}{Maximum distance allowed for a match. Expressedeither as integer, or as a fraction of the pattern length (will bereplaced by the smallest integer not less than the correspondingfraction), or a list with possible components\describe{\item{\code{all}:}{maximal (overall) distance}\item{\code{insertions}:}{maximum number/fraction of insertions}\item{\code{deletions}:}{maximum number/fraction of deletions}\item{\code{substitutions}:}{maximum number/fraction ofsubstitutions}}If \code{all} is missing, it is set to 10\%, the other componentsdefault to \code{all}. The component names can be abbreviated.}}\details{The Levenshtein edit distance is used as measure of approximateness:it is the total number of insertions, deletions and substitutionsrequired to transform one string into another.The function is a simple interface to the \code{apse} librarydeveloped by Jarkko Hietaniemi (also used in the Perl String::Approxmodule).}\value{Either a vector giving the indices of the elements that yielded amatch, of, if \code{value} is \code{TRUE}, the matched elements.}\author{David Meyer \email{David.Meyer@wu-wien.ac.at} (based on C codeby Jarkko Hietaniemi);modifications by Kurt Hornik.}\seealso{\code{\link{grep}}}\examples{agrep("lasy", "1 lazy 2")agrep("lasy", "1 lazy 2", max = list(sub = 0))agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2)agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2, value = TRUE)agrep("laysy", c("1 lazy", "1", "1 LAZY"), max = 2, ignore.case = TRUE)}\keyword{character}