I am trying to find an elegant way to use %in% and str_replace() to clean up gender. I know I can use regx() to do the same thing, but am looking at alternative ways to tackle the same problem.
My code is:
sex <- c("Male","girl","boy", "female")
male <- c("Male", "boy")
female <- c("girl", "female")
I know this code isn't right, but illustrates what I am trying to do
str_replace(sex, sex %in% male, "M")
str_replace(sex, sex %in% female, "F")
Any tips?