I have a list of values that I want to substitute with values from another list, wherever they appear. So for example, wherever "white" appears as a hair color, I want to use "light"; wherever "auburn" appears I want to use "brown. I can accomplish that with:
find_text = c("white", "auburn", "none")
replace_text = c("light", "brown", "bald")
starwars %>%
filter(gender == "feminine") %>%
select(c("name", "hair_color", "species")) %>%
mutate(hair_color = str_replace(hair_color, find_text[1], replace_text[1]),
hair_color = str_replace(hair_color, find_text[2], replace_text[2]),
hair_color = str_replace(hair_color, find_text[3], replace_text[3]),
)
I thought I could use fct_recode() but that also appears to require a single named string.
Is there a cleaner way to go about this?