title: Correct typos with R
body: <p>The following example is great to correct typos when you have a limited number of possible correct answers. In this case the expected answer can only be one of the following: positive, negative, neutral</p>
  
  <pre><code># Example of data typed manually that is prone to typos
  typed_manually &lt;- c("Positive", "positive ", "Positive", " positives", "neurtal", "negativv", "high")
  
  # To lower case
  typed_manually &lt;- tolower(typed_manually)
  
  # We specify what are the expected correct values
  expected_answers &lt;- c("positive", "negative", "neutral")
  
  # Associate typed_manually to expected_answers using a max distance of 2.
  # amatch is preferable to the adist function because letter permutations only count as distance =1
  library(stringdist)
  (i &lt;- amatch(typed_manually,expected_answers,maxDist=2))
  
  ## Compare side by side values typed manually and corrections
  data.frame(rawtext = typed_manually, code = expected_answers[i])
  </code></pre>
  
  <p>However, for many variables, we can't give a list of expected answers.
  For instance if the variable is the Employer of the person filling a form.</p>
  
  <p>What do you recommend in those situations?</p>
  
  <p>Do you think a system that starts with the most obvious errors and ask you if you want to merge these values is most suited?</p>
  
  <p>A text like the following would appear in the console:
  " "Coca-Cola Company" and "Cocal-Cola company" are most similar.
  Press "1" to merge them to "Coca-Cola Company" and "2" to merge them to "Cocal-Cola company". Enter "skip" to skip to next proposition"</p>
  
  <p>Would it make sense to have the order based on this ratio? 
  String distance/ word length </p>
  
  <p>Is there a smarter approach? Is there's already a package doing this? How could we implement this? </p>
  
  <p>Thanks!</p>
  
  <p>Note A: Code above is heavily inspired from <a href="http://cran.r-project.org/doc/contrib/de_Jonge+van_der_Loo-Introduction_to_data_cleaning_with_R.pdf" rel="nofollow">http://cran.r-project.org/doc/contrib/de_Jonge+van_der_Loo-Introduction_to_data_cleaning_with_R.pdf</a></p>