| lgrep {NCStats} | R Documentation |
Searches for matches to pattern within the character vector x and returns a logical vector indicating matches.
lgrep(pattern,x,...)
pattern |
A character string containing a regular expression or character string to be matched in the given character vector. Coerced by as.character() to a character string if possible. |
x |
A character vector where matches are sought, or an object which can be coerced by as.character() to a character vector. |
... |
Additional arguments to grep(). |
This function behaves similarly to grep() except that it returns a logical vector of the same length as x rather than a vector numeric positions as grep() does. This modification makes the result more useful for use with subset(), for example. For detailed use see the help for grep().
A logical vector of the same length as x that contains TRUE if the corresponding position in x partially matches pattern and FALSE if not a match.
Derek H. Ogle, dogle@northland.edu, but simply follows the suggestion of Vladimir Eremeev on the R-help mailing list on 21Aug07.
grep
## Prompt example on R-help
x <- c("w","ex","ee")
grep("e",x)
lgrep("e",x)
## First example from ?grep
grep("[a-z]", letters)
lgrep("[a-z]", letters)
data(iris)
iris.v <- iris[grep("v",iris$Species),]
view(iris.v)
iris.v1 <- subset(iris,lgrep("v",iris$Species))
view(iris.v1)