title: Using n-gram with R for error correction
body: <p>I'm working on a project to correct errors from scanned documents by an OCR and I would use n-grams with R.
  My algorithm would be first trained using a corpus with know mistakes to create a confusion
  matrix of 3-gram. So that when I have a particular 3-gram I can know what is the most probable 
  3-gram to replace it when there's a mistake.</p>
  
  <p>For know I only manage to create n-gram for a sentence:</p>
  
  <pre><code>library(tau)
  library(tm)
  
  txt1 &lt;- "The quick brown fox jumps over the lazy dog."
  
  r1&lt;-textcnt(txt1, method = "ngram", n=3)
  data.frame(counts = unclass(r1), size = nchar(names(r1)))
  format(r1)
  </code></pre>
  
  <p>But it gives me the frequency of each 3-gram without keeping the order and I  can't use it to create a confusion matrix.</p>