# Use a negative regex to rename all species other than "virginica" to "none"
iris %>%
recode_chr(
col = Species,
old_names = "vir",
new_name = "none",
regex = TRUE,
negate = TRUE) %>%
dplyr::count(Species)
# Specify old names using a regex
iris %>%
recode_chr(
col = Species,
old_names = "set|vir",
new_name = "other",
regex = TRUE) %>%
dplyr::count(Species)
Run the code above in your browser using DataLab