title: Keep only certain bigrams in document term matrix R
body: <p><strong>Question:</strong> How can I keep the bigram "no wonderful" only in the document term matrix or a list of bigrams (Terms) that I want to keep?</p>
  
  <p>I would like to apply this to a very large document term matrix. I tried converting the term matrix to a matrix but the vector size exceed 1000 Gb. </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>dd &lt;- data.frame(
  id = 10:13,
  text = c("No wonderful, then, that ever",
         "So that in many cases such a ",
         "But there were still other and",
         "Not even at the rationale"), stringsAsFactors = F)
  
  library(tm)
  library(RWeka)
  
  myReader &lt;- readTabular(mapping = list(content = "text", id = "id"))
  
  #create v corpus
  tm &lt;- VCorpus(DataframeSource(dd), readerControl = list(reader = myReader))
  
  #n-gram tokenizer
  Tokenizer &lt;- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
  
  #create document term matrix using Tokenizer
         dtm &lt;- TermDocumentMatrix(tm, control = list(tokenize = Tokenizer))
         inspect(dtm)
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>                             Docs
              Terms           10 11 12 13
              at the          0  0  0  1
              but there       0  0  1  0
              cases such      0  1  0  0
              even at         0  0  0  1
              in many         0  1  0  0
              many cases      0  1  0  0
              no wonderful    1  0  0  0
              not even        0  0  0  1
              other and       0  0  1  0
              so that         0  1  0  0
              still other     0  0  1  0
              such a          0  1  0  0
              that ever       1  0  0  0
              that in         0  1  0  0
              the rationale   0  0  0  1
              then that       1  0  0  0
              there were      0  0  1  0
              were still      0  0  1  0
              wonderful then  1  0  0  0
  </code></pre>