agrep(pattern, x, max.distance = 0.1, costs = NULL, ignore.case = FALSE, value = FALSE, fixed = TRUE, useBytes = FALSE) agrepl(pattern, x, max.distance = 0.1, costs = NULL, ignore.case = FALSE, fixed = TRUE, useBytes = FALSE)
pattern | a non-empty character string specifying the pattern to search for. It is interpreted as a literal sequence of characters if fixed is TRUE (the default). Otherwise, it is interpreted as a regular expression. | ||||||||||||||||||||||||
x | a vector of character strings in which to search. | ||||||||||||||||||||||||
max.distance |
the maximum allowed match distances. It can be an integer, a fraction, or a
list with the following five match distance components.
| ||||||||||||||||||||||||
costs | the integer cost of each inserted, deleted, or substituted character. It can be a numeric vector or a list with partially-matched names "insertions", "deletions", and "substitutions". Unspecified costs default to 1, so the default NULL value means that all three costs ("insertions", "deletions", and "substitutions") are 1. | ||||||||||||||||||||||||
ignore.case | a logical value. If TRUE, uppercase and lowercase characters are considered equivalent when matching. The default is FALSE. | ||||||||||||||||||||||||
value | a logical value. If TRUE, agrep returns the matched elements of x. If FALSE (the default), agrep returns the indices of the matched elements of x. | ||||||||||||||||||||||||
fixed | a logical value. If TRUE (the default), the pattern is represented as a literal sequence of characters. If FALSE, the pattern is represented as a regular expression. | ||||||||||||||||||||||||
useBytes |
a logical value.
|
agrep | if value=FALSE, returns a numeric vector indicating which elements of x matched pattern. (The return value numeric(0) indicates that there are no matches). If value=TRUE, returns the matching elements of x. (If the matching elements are not character data, they are converted to character data.) |
agrepl | returns a logical vector indicating which elements of x matched pattern. These return values can be used as a subscript to retrieve the matching elements of x. |
agrep("life", "a live b") agrep("life", c("a live b", "a life b")) agrep("life", c("a live b", "a life b"), max = list(sub = 0)) agrep("lifye", c("a live b", "a life b"), max = list(all = 0.1)) agrep("lifye", c("a live b", "a life b"), max = list(all = 2))agrep("liyfe", c("a live", "A", "a Live"), max = 2) agrep("liyfe", c("a live", "A", "a Live"), max = list(all = 0.2)) agrep("liyfe", c("a live", "A", "a LiVE"), max = 2, value = TRUE) agrep("liyfe", c("a live", "A", "a LIVE"), max = 2, ignore.case = TRUE)
sName <- c("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Louisiana", "Delaware", "Florida", "Georgia") agrep("ia$", sName, value=TRUE, fixed = FALSE) ## pattern is interpreted as a regular expression. ## returns all names that end in "ia" approximately, it is not equivalent to ## grep(), which returns the states that end in "ia" exactly!
agrep("ia$", sName, value=TRUE, fixed = FALSE, max=0) ## with max=0, returns the same values as grep
agrep("ia$", sName, value=TRUE) ## pattern is interpreted as literal character string, the result is also ## different from above example.