Search code examples
rstringdist

Calculating string similarity as a percentage


The given function uses "stringdist" package in R and tells the minimum changes needed to change one string to another. I wish to find out how much similar is one string to another in "%" format. Please help me and thanks.

stringdist("abc","abcd", method = "lv")

Solution

  • You can use RecordLinkage package and use the function levenshteinSim, i.e.

    #This gives the similarity
    RecordLinkage::levenshteinSim('abc', 'abcd')
    #[1] 0.75
    
    #so to get the distance just subtract from 1, 
    1 - RecordLinkage::levenshteinSim('abc', 'abcd')
    #[1] 0.25