title: Count Number of Occurrences of words from a list in text entries (R)
body: <p>I am working with a set of tweets pulled from Twitter's public API and am trying to do a bit of text analysis.</p>
  
  <p>Currently, I have a data frame for the tweets and the text is housed in the column titled <code>total.tweets$text</code> and has entries like:</p>
  
  <p>I have a dictionary of sentiment-words (i.e. - positive, negative, etc) and pulled each column in from the csv file as a string:</p>
  
  <blockquote>
    <p>posTerms &lt;- toString(na.omit(lexicon$Positiv))</p>
  </blockquote>
  
  <p>I would like to count the number of times any positive from this file appears in each tweet, creating a new column for that count that would be <code>total.tweets$PosCount</code>.</p>
  
  <p>For example, a tweet that reads: <code>Our greatest glory is not in never falling, but in rising every time we fall #confucius #entrepreneurship</code></p>
  
  <p>If <code>greatest</code> <code>glory</code> and <code>rising</code> are in the positive words, the PosCount would be 3.</p>
  
  <p>I tried using <code>strcount</code> as below:</p>
  
  <pre><code>posTerms &lt;- toString(na.omit(lexicon$Positiv))
  </code></pre>
  
  <p>total.tweets$Positiv &lt;- str_count(total.tweets$text, paste(posTerms,collapse='|'))</p>
  
  <p>But keep getting this error:</p>
  
  <blockquote>
    <p>Error: invalid regular expression 'ABIDE, ABILITY, ABLE, ABOUND,. . . </p>
  </blockquote>
  
  <p>Any ideas would be greatly appreciated!</p>