I have created a dataframe like below:
dfm = data.frame (names = c('email', 'Facebook', 'walmart', 'target', 'instagram', 'costco'))
And in that I want to create a new column source. When names are facebook, instagram or email, source is media. When names are costco,walmart or target, the source is store.
I use the following case_when() and str_detect(). I need to the str_detect to be case insensitive. So below is my code.
mutate(source = case_when( str_detect(names, fixed('email|facebook|instagram', ignore_case = T))~'media',
str_detect(names, 'walmart|costco|target')~ 'store'))
I do not understand why it did not work. Does anyone know why?
I tried the code below, it returns TRUE:
str_detect('Facebook', fixed('facebook', ignore_case = T))