Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204876

How do I count the number of words from a list mentioned in a data frame in R

$
0
0

I have a data frame with a review and text column with multiple rows. I also have a list containing words. I want a for loop to examine each row of the data frame to sum the number of words found in the from the list. I want to keep each row sum separated by the row and place the results into a new result data frame.

#Data Frame
Review           Text
1           I like to run and play.
2           I eat cookies.
3           I went to swim in the pool.
4           I like to sleep.
5           I like to run, play, swim, and eat.

#List Words
Run
Play
Eat
Swim

#Result Data Frame
Review      Count
1            2
2            1
3            1
4            0
5            4

Viewing all articles
Browse latest Browse all 204876

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>