| grep_case | R Documentation |
Switch-style recoding of values with string pattern matching
grep_case(x, ..., preserve = FALSE, default = NA)
x |
A vector |
... |
<
|
preserve |
If |
default |
If |
A vector of the same length as x.
grep_case_fct() to return a factor and
grep_case_list() to return a list
fn_case(), to apply a function other than grepl() to each case
switch_case() to recode values with exact matching
in_case(), a pipeable alternative to dplyr::case_when()
switch() and grepl(), which inspired this function
words <- c("caterpillar", "dogwood", "catastrophe", "dogma")
grep_case(
words,
"cat" ~ "feline",
"dog" ~ "canine"
)
caps_words <- c("caterpillar", "dogwood", "Catastrophe", "DOGMA")
grep_case(
caps_words,
"cat" ~ "feline",
"dog" ~ "canine",
ignore.case = TRUE
)
countries <- c(
"France", "Ostdeutschland", "Westdeutschland", "Nederland",
"Belgie (Vlaanderen)", "Belgique (Wallonie)", "Luxembourg", "Italia"
)
grep_case(
countries,
"Deutschland" ~ "Germany",
"Belgi(qu)?e" ~ "Belgium",
"Nederland" ~ "Netherlands",
"Italia" ~ "Italy",
preserve = TRUE,
ignore.case = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.