Hi,
Ive only been using R for a short period of time and this is my first post so apologies if i have tagged/catagorised wrong.
My problem is that i have to create a new variable depending on what words are within other variables. Some of these are very specific e.g. if UTM.source = "PR" then Channel = "PR". However some are more complex e.g. If UTM. source or UTM. medium contain "print" but don't contain "local" then Channel = "DM". I have been trying to use a nested ifelse statement with grepl && !grepl but no variations are working correctly. I should give my whole code, but here are a few lines to show roughly what i have been trying. I am getting no error messages but the output isnt giving me what i need.
mutate(Channel = ifelse(grepl("Email", UTM.source, ignore.case = TRUE) && !grepl("wholesale" , UTM.source, ignore.case = TRUE)
| grepl("Email", UTM.medium, ignore.case = TRUE) && !grepl("wholesale", UTM.medium, ignore.case = TRUE), "Email",
ifelse(grepl("Print", UTM.source, ignore.case = TRUE) | grepl ("print", UTM.medium, ignore.case = TRUE)
&& !grepl("local" , UTM.source, ignore.case = TRUE) | !grepl("local", UTM.medium, ignore.case = TRUE), "DM",
im essentially hoping there with be a way to say "if var1 or var2 contain string1, but don't contain string2 then var3 = string3