title: Count words in a text based on a lexicon
body: <p>I have this kind of data:</p>
  
  <pre><code>library(dplyr)
  
  glimpse(samp)
  Observations: 10
  Variables: 2
  $ text &lt;chr&gt; "@VirginAmerica What @dhepburn said.", "@VirginAmerica plus you've ...
  $ airline_sentiment &lt;chr&gt; "neutral", "positive", "neutral", "negative", "negative", "negative...
  </code></pre>
  
  <p>I want to compare the occurrence of the words in the text variable with the words in a lexicon, i.e. I want to count how often a certain word appears in the text based on the lexicon. </p>
  
  <p>The lexicon looks like this</p>
  
  <pre><code>library(lexicon)
  hash_sentiment_sentiword[1:5]
               x     y
  1:    365 days -0.50
  2:    366 days  0.25
  3:         3tc -0.25
  4:  a fortiori  0.25
  5: a good deal  0.25
  </code></pre>
  
  <p>I know there are functions like <code>str_detect</code>. However, from this, I only get true/false values.</p>
  
  <p>The result should be like this (pseudo code):</p>
  
  <pre><code>   text     x        y      n    
  1. word 1   word 1   score  2
  2. word 2   word 2   score  1
  3. word 3   word 3   score  10
  4. word 4   word 4   score  0
  5. word 5   word 5   score  0
  ...
  </code></pre>
  
  <p>text: A word of the text column from <code>samp</code>; 
  x and y: x and y column from <code>hash_sentiment_sentiword</code>; 
  n: Frequency of the appearance of a word of x in the text, For example, the word "awesome" is in x and appears one time in the text. So for "awesome" n would be 1. "country" is not in x but in the text. So n would be 0. </p>
  
  <p>Here is a small <code>dput()</code>:</p>
  
  <pre><code>dput(samp)
  
  structure(list(text = c("@VirginAmerica Thanks!", "@VirginAmerica SFO-PDX schedule is still MIA.", 
  "@VirginAmerica So excited for my first cross country flight LAX to MCO I've heard nothing but great things about Virgin America. #29DaysToGo", 
  "@VirginAmerica  I flew from NYC to SFO last week and couldn't fully sit in my seat due to two large gentleman on either side of me. HELP!", 
  "I &lt;U+2764&gt;&lt;U+FE0F&gt; flying @VirginAmerica. &lt;U+263A&gt;&lt;U+FE0F&gt;&lt;U+0001F44D&gt;", 
  "@VirginAmerica you know what would be amazingly awesome? BOS-FLL PLEASE!!!!!!! I want to fly with only you."
  ), airline_sentiment = c("positive", "negative", "positive", 
  "negative", "positive", "positive")), row.names = 15:20, class = "data.frame")
  </code></pre>