lgrep {NCStats}R Documentation

Pattern matching.

Description

Searches for matches to pattern within the character vector x and returns a logical vector indicating matches.

Usage

lgrep(pattern,x,...)

Arguments

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().

Details

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().

Value

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.

Author(s)

Derek H. Ogle, dogle@northland.edu, but simply follows the suggestion of Vladimir Eremeev on the R-help mailing list on 21Aug07.

See Also

grep

Examples

## 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)

[Package NCStats version 0.0-12 Index]