title: String matching in RStudio
body: <p>I am having trouble with the following scenario. I have a dataframe <code>df</code> that has multi-word strings in <code>var1</code>.  I want to keep only the words from <code>var1</code> if that word is in <code>chr</code>. For example, the first row of <code>var1</code> has "car tv dog" and I want to delete the word "dog" because it is not in <code>chr</code>.</p>
  
  <p>My dataframe:</p>
  
  <pre><code>id &lt;- c(1,2,3)
  var1 &lt;- c("car tv dog","cat water mouse","pen wire fish")
  df &lt;- data.frame(id,var1)
  </code></pre>
  
  <p>Words I want to keep:</p>
  
  <pre><code>chr&lt;-"car aaa bbb ccc ddd qqq www eee rrr pen cat ttt fish tv"
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>want &lt;- c("car tv","cat","pen fish")
  dfWant &lt;- data.frame(id, var1, want) 
  </code></pre>
  
  <p>Any help will be much appreciated.</p>