-2

I have a list of city names that are misspelled by users in a text entry box field for example (Chiqago, Neww jork or also Niu yorc, etc). I would like to know if R can solve this kind of problem that receive a badly written city and transforms into a correct city name.

Input city : Chiqago, Neww jork, Niu yorc, St Fransis
Output city: Chicago, New York, New York, San Francisco
Newl
  • 310
  • 2
  • 12
  • 2
    one quick way, i.e., minimize mahalanobis (or similar) distance on a known correct "dictionary", might do the trick for easy cases – runr Apr 16 '19 at 14:28

1 Answers1

0

I recommend looking into the stringr package. You can use str_detect to find the incorrect pattern and str_replace or str_replace_all to replace it with the correct pattern.

https://cran.r-project.org/web/packages/stringr/vignettes/stringr.html

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82