I am working with text data, and looking for a solution to a filtering problem.
I have managed to find a solution which filters for rows that contain 'Word 1' OR 'Word 2'
Here's the reproducible code
df=data.frame(UID=c(1,2,3,4,5),Text=c("the quick brown fox jumped over the lazy dog",
"long live the king",
"I love my dog a lot",
"Tomorrow will be a rainy day",
"Tomorrow will be a sunny day"))
#Filter for rows that contain "brown" OR "dog"
filtered_results_1=dplyr::filter(df, grepl('brown|dog', Text))
However when I filter for rows that contain both 'Word 1' AND 'Word 2', it doesn't work.
#Filter for rows that contain "brown" AND "dog"
filtered_results_2=dplyr::filter(df, grepl('brown & dog', Text))
Cannot figure out the right syntax for this one, any help would be appreciated.