I have a dataframe with different text excerpts.
I am looking to subset all the observations that contain at least 2 terms of my little dictionary ("poverty|report|alarming|inflation"), or the same term twice (like report occurs twice in a text).
texts <- data.frame(text = c("report highlights that poverty is widespread", "there is inflation", "alarming reports", "thanks for listening"), id = 1:4, group = 4:7)
texts[grepl("poverty|report|alarming|inflation", texts$text, ignore.case=T),]
# I don't want this: text id group
#1 report highlights that poverty is widespread 1 4
#2 there is inflation 2 5
#3 alarming reports 3 6
but i want this:
# text id group
#1 report highlights that poverty is widespread 1 4
#3 alarming reports 3 6
Try this
base R
approach:Output: