title: Matching a list of phrases to a corpus of documents and returning phrase frequency
body: <p>I have a list of phrases and a corpus of documents.There are 100k+ phrases and 60k+ documents in the corpus. The phrases are might/might not present in the corpus. I'm looking forward to find the term frequency of each phrase present in the corpus.</p>
  
  <p>An example dataset:</p>
  
  <pre><code>Phrases &lt;- c("just starting", "several kilometers", "brief stroll", "gradually boost", "5 miles", "dark night", "cold morning")
  Doc1 &lt;- "If you're just starting with workout, begin slow."
  Doc2 &lt;- "Don't jump in brain initial and then try to operate several kilometers without the need of worked out well before."
  Doc3 &lt;- "It is possible to end up injuring on your own and carrying out more damage than good."
  Doc4 &lt;- "Instead start with a brief stroll and gradually boost the duration along with the speed."
  Doc5 &lt;- "Before you know it you'll be working 5 miles without any problems."
  </code></pre>
  
  <p>I am new to text analytics in R and have approached this problem on the lines of Tyler Rinker's solution to this <a href="https://stackoverflow.com/questions/8996513/r-text-mining-counting-the-number-of-times-a-specific-word-appears-in-a-corpus/29392168#29392168">R Text Mining: Counting the number of times a specific word appears in a corpus?</a>.</p>
  
  <p>Here's my approach so far:</p>
  
  <pre><code>library(tm)
  library(qdap)
  Docs &lt;- c(Doc1, Doc2, Doc3, Doc4, Doc5)
  text &lt;- removeWords(Docs, stopwords("english"))
  text &lt;- removePunctuation(text)
  text &lt;- tolower(text)
  corp &lt;- Corpus(VectorSource(text))
  Phrases &lt;- tolower(Phrases)
  word.freq &lt;- apply_as_df(corp, termco_d, match.string=Phrases)
  mcsv_w(word.freq, dir = NULL, open = T, sep = ", ", dataframes = NULL,
          pos = 1, envir = as.environment(pos))
  </code></pre>
  
  <p>When I'm exporting the results in csv, it is only giving me whether phrase 1 is present in any of the docs or not.</p>
  
  <p>I'm expecting an output as below (excluding the non-matching phrases):</p>
  
  <pre><code>Docs      Phrase1     Phrase2    Phrase3    Phrase4    Phrase5
  1         0           1          2          0          0
  2         1           0          0          1          0
  </code></pre>