Search code examples
rlevenshtein-distancestringdist

String matching using stringdist in r?


I want to match and then later replace the string to the closest match. I am using the stringdist library. Below is my code

stringdistmatrix("2 ltr thums up", c("solar thyme 30g", "Thums Up 2 L"), method = "lv")

It gives the output as below:

[,1] [,2]
 8   12

It means that "solar thyme 30g" is closer to "2 ltr thums up" but in reality "Thums Up 2 L" should be closer. Shall I change the levenshtein method to something else?


Solution

  • I tried the method = 'cosine' and the output looks fine.