I use STR_DETECT with IFELSE to create a new column called "function_YN". However, since I have to throw in a large number of wild cards, my script became long and cumbersome. Any way to simply this? Below is just a shortened version of the coding and I actually have more key words to detect.
library(dplyr)
library(stringr)
df$function_YN <-
ifelse(str_detect(df$JOB_TITLE, "POLICE"),"YES",
ifelse(str_detect(df$JOB_TITLE, "FIREFIGHTER"),"YES",
ifelse(str_detect(df$JOB_TITLE, "DETECTIVE"),"YES",
ifelse(str_detect(df$JOB_TITLE, "PUBLIC SAFETY"),"YES",
ifelse(str_detect(t1$JOB_TITLE, "CAPTAIN"),"YES", "NO")))))