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

R - Counting total occurrences of word from list that appears in data frame, and grouped

$
0
0

I have a data frame like this:

ID   Word
1    Tree
1    House
1    Tree
2    Snail
2    Tree
3    Car

And I have a list of keywords I want to check for:

(House, Tree, Bird)

I want to know how many times for each ID, any word in my list of keywords appears.

I.e. the word House, Tree or Bird appears 3 times in ID(1), and House, Tree or Bird appears only once in ID(2), and there are no occurrences in ID(3)

ID   Count
1     3
2     1
3     0

I am not sure how to tackle this. I know how to count the number of times a word appears within each ID, but not how many times the words from another list appear.

Thank you for any suggestions/guidance etc.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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