grepl is an R function that searches for matches to argument pattern within each element of a character vector.
grepl
returns TRUE if a string contains the pattern, otherwise FALSE; if the parameter is a string vector, returns a logical vector (match or not for each element of the vector).
Description
grepl(pattern, x, ignore.case = FALSE, perl = FALSE,
fixed = FALSE, useBytes = FALSE)
pattern
: regular expression, or string for fixed=TRUEx
: string, the character vectorignore.case
: case sensitive or notperl
: logical. Should perl-compatible regexps be used? Has priority over extendedfixed
: logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting argumentsuseBytes
: logical. If TRUE the matching is done byte-by-byte rather than character-by-character
Example
> x <- "line 4322: He is now 25 years old, and weights 130lbs"
> y <- grepl("\\d+",x)
> y
Reference
- R Documentation