I am trying to assign similarity score based on comparison between 2 strings. Is there a function for the same in R. I am aware of such a function in SAS by the name of SPEDIS. Please let me know if there is such a function in R.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The function adist computes the Levenshtein edit distance between two strings. This can be transformed into a similarity metric as 1 – (Levenshtein edit distance / longer string length).
The
levenshteinSimfunction in the RecordLinkage package also does this directly, and might be faster thanadist.ETA: Interestingly, while
levenshteinDistin the RecordLinkage package appears to be slightly faster thanadist,levenshteinSimis considerably slower than either. Using the rbenchmark package:This overhead is due simply to the code for
levenshteinSim, which is just a wrapper aroundlevenshteinDist:FYI: if you are always comparing two strings rather than vectors, you can create a new version that uses
maxinstead ofpmaxand shave ~25% off the running time:Long story short- there is little difference between
adistandlevenshteinDistin terms of performance, though the former is preferable if you don’t want to add package dependencies. How you turn it into a similarity measure does have a bit of an effect on performance.