Thank you in advance for any help!
I have a dataframe about book bans with an original column titled "reason" but the values from the dataset are inconsistently written. I have some code written that is creating a new column "specific reason" that is aggregating all the "reason" values that include certain words to make categories (ie: "race" and "racial" could be renamed as "racism" in the new column). How can I add more words/categories to my new column ("specific reason")? The code I'm working with now is below, but I'm not sure how to add to it. I'd also like to convert all the blank values in the column to be named "NA".
add_specific_reason <- function(messy_reason) {
case_when(str_detect(messy_reason, "nude|sex|nudity") == TRUE
& str_detect(messy_reason, "\brace\b|racial") ~ "sex; race", str_detect(messy_reason, "nude|sex|nudity") == TRUE ~ "sex",
str_detect(messy_reason, "\brace\b|racial") == TRUE ~ "race",
str_detect(messy_reason, "violent|violence") == TRUE ~ "violence",
)
}