How to return the top 2 tags from separate list within a dataframe?

Let's say I have a dataframe with comments about a pizzaria. I'd like to apply a list of tags to this dataframe to highlight the top tagged words, not case sensitive.

For example, the dataframe is:

ID	String
1	"The pizza was delicious"
2	"I loved the appetizer"
3	"Meatballs please on my pizza"
4	"Yum"
5	"Pineapple on my pizza"
6	"Keep the pineapple away"
7	"Peperoni Pizza!"

The tag list is:

Tag List

The ideal output would be:

ID String Tag 1 Tag 2
1 "The pizza was delicious" PIZZA
2 "I loved the appetizer"
3 "Meatballs please on my pizza" MEATBALL PIZZA
4 "Yum"
5 "Pineapple on my pizza" PINEAPPLE
6 "Keep the pineapple away" PINEAPPLE
7 "Peperoni Pizza!" PEPERONI PIZZA

How could I go about accomplishing this?

Any help would be greatly appreciated!

Solved myself....

dataframe: responses
tag dataframe: tags

temp <- tags
for (each in 1:nrow(responses)) {
temp$Count <- str_count(responses$String[each], tags$Tag List)
temp <- temp[order(-temp$Count, temp$Tag List),]
responses$Tag_1[each] <- ifelse(temp$Count[1]=="0","",temp$Tag List[1])
responses$Tag_2[each] <- ifelse(temp$Count[2]=="0","",temp$Tag List[2])

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.