Description Usage Arguments Details Value Author(s) Examples
a collection of multi-grep methods which make use of multiple patterns,
as opposed to grep
's single pattern.
1 2 3 4 5 6 7 8 9 10 | mgrep(patterns, x, ignore.case = FALSE, perl = FALSE, value = FALSE,
fixed = FALSE, useBytes = FALSE, invert = FALSE, nomatch = NA)
mgrepl(patterns, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE)
grepf(patterns, x, ignore.case = FALSE, perl = FALSE, value = FALSE,
fixed = FALSE, useBytes = FALSE, invert = FALSE)
grepfl(patterns, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE,
useBytes = FALSE, invert = FALSE)
|
patterns |
a character vector of at least one pattern. |
x |
a character vector where matches are sought, or an object
which can be coerced by |
ignore.case |
if |
perl |
logical. Should Perl-compatible regexps be used? |
value |
if |
fixed |
logical. If |
useBytes |
logical. If |
invert |
logical. If |
nomatch |
if a pattern isn't found, what should be returned for that element in the
result |
mgrep
: mgrep
takes a vector of patterns
, and searches for each within
x
, returning either the matching indices into x
, or values (if value=TRUE
),
for each pattern in a list
of length(patterns)
.
Just like mget
as the multi-version of get
,
there is a nomatch
parameter controlling what to do if no match for a particular
pattern is found.
mgrepl
: grep for multiple patterns
, and return logical if each pattern is present
in any value of x
grepf
: grep -f for R. ie return the elements of x
which match any of the patterns
.
grepfl
: combo of grepf
+ grepl
ie which
elements of x
match >=1
of the patterns
, as
a logical vector
mgrep
: a list
with one element per pattern in the patterns
vector.
Each element of this list
is the value returned by grep
for each pattern,
OR nomatch
if nothing is found. NB this is different from the default
behaviour of grep
, which returns numeric(0)
when no match is found.
mgrepl
: a logical vector, length = length(patterns)
, indicating whether each
pattern was found in x
grepf
: if value=FALSE
, a numeric
vector of
indices in 1:length(x)
which match any of the patterns
,
or, if value=TRUE
, return a character
vector of the elements
of x
which match any
of the patterns.
grepfl
: a logical
vector, of length=length(x)
,
indicating whether each of the elements in x
match any of the
patterns
. if invert=TRUE
, then the logical vector indicates
which elements did not match any of the patterns
.
Mark Cowley, 23 Sept 2005
Mark Cowley, 2011-02-18
Mark Cowley, 2011-02-18
Mark Cowley, 2011-02-18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # use the state.name example data
mgrep(c("New","^V", "Iran"), state.name)
mgrep(c("New","^V", "Iran"), state.name, value=TRUE)
# nomatch
mgrep(c("New","^V", "Iran"), state.name, nomatch=NULL)
mgrep(c("New","^V", "Iran"), state.name, value=TRUE, nomatch=NULL)
# use the state.name example data
mgrepl(c("New","^V", "Iran"), state.name)
# New ^V Iran
# TRUE TRUE FALSE
# use the state.name example data
grepf(c("New","^V", "Iran"), state.name)
# [1] 29 30 31 32 45 46
grepf(c("New","^V", "Iran"), state.name, value=TRUE)
grepf(c("New","^V", "Iran"), state.name, invert=TRUE)
# use the state.name example data
grepfl(c("New","^V", "Iran"), state.name)
grepfl(c("New","^V", "Iran"), state.name, invert=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.