So if I have the following
list <- c("catdog","chicken","poop")
names <- c("Fabio","John","Jack")
df <- data.frame(names, list, stringsAsFactors=FALSE)
names list
1 Fabio catdog
2 John cat
3 Jack dog
Assuming list is a column of strings. I want to know how can I return rows where "cat" AND "dog" after appearing once as a pair they may appear more times. I tried:
want <- c("cat","dog")
df[grepl(paste(want,collapse="&"),df$list),]
I know this works with "|" for some reason its not working with "&". Let me know if anyone can help with this. Thanks!