title: Produce a DocumentTermMatix that includes given terms in R
body: <p>I'm producing a DocumentTermMatrix using <code>tm</code> on a corpus, using only terms which occur quite frequently. (ie MinDocFrequency=50)</p>
  
  <p>Now I want to produce a DTM with a different corpus, but counting exactly the same terms as the previous one, no extra and no fewer. (to cross-validate)</p>
  
  <p>If I use the same method to produce the DTM as with the first corpus, I end up including either more or less terms, or just different ones because they're at a different frequency to the original corpus.</p>
  
  <p>How can I go about doing this? I need to specify which terms to count somehow, but I don't know how.</p>
  
  <p>Thanks to anyone who can point me in the right direction,</p>
  
  <p>-N</p>
  
  <p>EDIT: I was asked for a reproducible example, so I've pasted some example code here <a href="http://pastebin.com/y3FDHbYS" rel="nofollow">http://pastebin.com/y3FDHbYS</a>
  Re-edit:</p>
  
  <pre><code> require(tm)
   text &lt;- c('saying text is good',
            'saying text once and saying text twice is better',
            'saying text text text is best',
            'saying text once is still ok',
            'not saying it at all is bad',
            'because text is a good thing',
            'we all like text',
            'even though sometimes it is missing')
  
  validationText &lt;- c("This has different words in it.",
                       "But I still want to count",
                       "the occurence of text",
                       "for example")
  
  TextCorpus &lt;- Corpus(VectorSource(text))
  ValiTextCorpus &lt;- Corpus(VectorSource(validationText))
  
  Control = list(stopwords=TRUE, removePunctuation=TRUE, removeNumbers=TRUE, MinDocFrequency=5)
  
  TextDTM = DocumentTermMatrix(TextCorpus, Control)
  ValiTextDTM = DocumentTermMatrix(ValiTextCorpus, Control)
  </code></pre>
  
  <p>This, however just shows the method I'm already familiar with for producing a corpus, and as a result the two DTMs, (TextDTM and ValiTextDTM) contain different terms. What I'm trying to achieve is counting the same terms in both corpuses, even if they are much less frequent in the validation one. In the example then, I'd be trying to count occurrences of the word "text", even though this would produce a very sparse matrix in the validation case.</p>