Detect whether multiple patterns occur in a character vector
Arguments
- patterns
vector of 1+ patterns to search for, passed one at a time to
gregexec()- x
a vector of character strings to search within
- ignore.case
passed to
gregexec()- rowperx
whether to return a matrix with one row per element of
xand one column per pattern, or instead return a vector with one element per pattern summarizing across all ofx
Value
If rowperx = TRUE, a logical matrix with one row per element of
x and one column per pattern. If rowperx = FALSE, a logical vector
with one element per pattern.
Examples
grepn("x", c("0 abc", "1 uppercase X", "1 xyz", "2 xx", "3 x x x"))
grepn("x", c("0 abc", "1 uppercase X", "1 xyz", "2 xx", "3 x x x"), ignore.case = FALSE)
grepns(c("x", "y"), c("yes", "yx", "this 1 has some x x xxxxx"))
grepns(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = TRUE, count1perx = TRUE)
grepns(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = FALSE, count1perx = TRUE)
grepns(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = TRUE, count1perx = FALSE)
grepns(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = FALSE, count1perx = FALSE)
grepls(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = TRUE)
grepls(c("hi", "other", 'x'), c("said hi ther hi hi hi e", 'hi', 'another', 'none'),
rowperx = FALSE)