chr.grep | R Documentation |
This function searches for matches to the character vector specified in
pattern
within each element of the character vector x
.
chr.grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE,
fixed = FALSE, useBytes = FALSE, invert = FALSE, check = TRUE)
chr.grepl(pattern, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE,
useBytes = FALSE, check = TRUE)
pattern |
a character vector with character strings to be matched. |
x |
a character vector where matches are sought. |
ignore.case |
logical: if |
perl |
logical: if |
value |
logical: if |
fixed |
logical: if |
useBytes |
logical: if |
invert |
logical: if |
check |
logical: if |
Returns a integer vector with the indices of the mathces when value = FALSE
,
character vector containing the matching elements when value = TRUE
, or
a logical vector when using the chr.grepl
function.
Takuya Yanagida
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole
chr.gsub
, chr.omit
, chr.trim
chr.vector <- c("James", "Mary", "Michael", "Patricia", "Robert", "Jennifer")
# Example 1: Indices of matching elements
chr.grep(c("am", "er"), chr.vector)
# Example 2: Values of matching elements
chr.grep(c("am", "er"), chr.vector, value = TRUE)
# Example 3: Matching element?
chr.grepl(c("am", "er"), chr.vector)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.