title: Count number of occurrences of words from a list in a data frame in R
body: <p>I am working on a little program in R which allows me to count the number of occurrences from a list in a data frame.</p>
  
  <p>I therefore import my data frame and my word list as follows.</p>
  
  <pre><code>df &lt;- read.csv("tweets.csv")
  wordlist &lt;- read.csv("wordlist.csv")
  </code></pre>
  
  <p>My idea was to use a "for"-loop which runs through all the words in the wordlist, counts their occurrences in the df data frame and then adds the number to the existing wordlist.</p>
  
  <pre><code>for (id in wordlist) 
  {
  wordlist$frequency &lt;- sum(stri_detect_fixed(df$text, wordlist$word))
  }
  </code></pre>
  
  <p>Clearly this doesn't work. Instead it adds the frequencies of ALL words in my wordlist to each of the words in the wordlist data frame which looks something like:</p>
  
  <pre><code>id  word     freuquency
  1   the      1290
  2   answer   1290
  3   is       1290
  4   wrong    1290
  </code></pre>
  
  <p>I know it has to do something with the running variable in my for-loop. Any help is appreciated :)</p>