My dataframe(df) looks like this:
Comments
-----------------
1 | comment1
2 | comment2
3 | comment3
4 | comment4
...
I have created 2 lists are follows:
list1<-c("money","finance","aid")
list2<-c("major","degree")
I want to search through rows in a datframe which has comments from different persons. When any of the words in list1
are found in a particular row, counter1
should increment and when words in list2
are found counter2
should increment
I want to get results as:
counter1=10 ; counter2=25
Note: I don't wish to increment the counter at each frequency of words. For example, if a comment contains both "money" and "finance" the counter should increment only once. But if it has "money" and "major", counter1 and counter2 both should increment.