title: Ngrams words with TFIDF - Phrases detection using R
body: <pre><code>TrigramTokenizer &lt;-function(x) NGramTokenizer(x, 
                                              Weka_control(min = 1, max = 3))
  Text = c( "Ab Hello world","Hello ab",  "ab" )
  tt = Corpus(VectorSource(Text))
  tdm &lt;- TermDocumentMatrix( tt, 
                         control = list(wordLengths=c(1,Inf), tokenize = TrigramTokenizer))
  inspect(tdm)
  
  
  Output
  
  &lt;&lt;TermDocumentMatrix (terms: 7, documents: 3)&gt;&gt;
  Non-/sparse entries: 10/11
  Sparsity           : 52%
  Maximal term length: 14
  Weighting          : term frequency (tf)
  
              Docs
  Terms            1 2 3
    ab             1 1 1
    ab hello       1 0 0
    ab hello world 1 0 0
    hello          1 1 0
    hello ab       0 1 0
    hello world    1 0 0
    world          1 0 0
  </code></pre>
  
  <p>This gives me the term frequency however, I would like to have the code basis tfidf like below code. Though I used dtm in the first and tdm in the second, imagine both are tdm and TermDocumentMatrix</p>
  
  <pre><code>dtm &lt;- DocumentTermMatrix(tt, control = list(weighting = weightTfIdf))
  tdm &lt;- TermDocumentMatrix( tt, 
                         control = list(wordLengths=c(1,Inf), tokenize = TrigramTokenizer))
  </code></pre>
  
  <p>My question is how to merge both these codes. I have long list of customer verbatim and by using the first code I could only get the output as shown in the first table however, it has lot of junk. was thinking doing it basis tfidf would resolve the issue. Please help me with this. Alternative way of doing this is also welcome. </p>
  
  <p>Thanks in advance</p>