I have a column with unique email domains. (e.g. @comp1.com, @comp2.com, ...)
I have another dataset with an email column, that includes many emails. Some of the domains will be prensent in the domain df, some will not.
I would like to create a new column "target_email", where it would return TRUE if the email is part of those targeted domains, and FALSE if not.
I have tried:
df$target_email<-grepl(domain$Email, df$Email)
df$target_email<-ifelse(grepl(domain$Email, df$Email), "TRUE", "FALSE")
df$target_email<-sapply(domain$Email, \(string) any(grepl(string, df$target_email, fixed = TRUE)))
These all return an error:
argument 'pattern' has length > 1 and only the first element will be used
or
replacement has 160 rows, data has 28446
Edit: Let's say we want to isolate emails that belong to a FAANG company
df$email<-c("matt@apple.com", "tash@amazon.com", "a@coke.com", "b@netflix.com", "c@pepsi.com")
domains$email<-c("apple.com", "netflix.com", "amazon.com", "google.com")
I want:
df$target_email<-c("True", "True", "False", "True", "False")