Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:16:02+00:00 2026-06-07T19:16:02+00:00

I am trying to assign similarity score based on comparison between 2 strings. Is

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:16:04+00:00Added an answer on June 7, 2026 at 7:16 pm

    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 levenshteinSim function in the RecordLinkage package also does this directly, and might be faster than adist.

    library(RecordLinkage)
    > levenshteinSim("apple", "apple")
    [1] 1
    > levenshteinSim("apple", "aaple")
    [1] 0.8
    > levenshteinSim("apple", "appled")
    [1] 0.8333333
    > levenshteinSim("appl", "apple")
    [1] 0.8
    

    ETA: Interestingly, while levenshteinDist in the RecordLinkage package appears to be slightly faster than adist, levenshteinSim is considerably slower than either. Using the rbenchmark package:

    > benchmark(levenshteinDist("applesauce", "aaplesauce"), replications=100000)
                                             test replications elapsed relative
    1 levenshteinDist("applesauce", "aaplesauce")       100000   4.012        1
      user.self sys.self user.child sys.child
    1     3.583    0.452          0         0
    > benchmark(adist("applesauce", "aaplesauce"), replications=100000)
                                   test replications elapsed relative user.self
    1 adist("applesauce", "aaplesauce")       100000   4.277        1     3.707
      sys.self user.child sys.child
    1    0.461          0         0
    > benchmark(levenshteinSim("applesauce", "aaplesauce"), replications=100000)
                                            test replications elapsed relative
    1 levenshteinSim("applesauce", "aaplesauce")       100000   7.206        1
      user.self sys.self user.child sys.child
    1      6.49    0.743          0         0
    

    This overhead is due simply to the code for levenshteinSim, which is just a wrapper around levenshteinDist:

    > levenshteinSim
    function (str1, str2) 
    {
        return(1 - (levenshteinDist(str1, str2)/pmax(nchar(str1), 
            nchar(str2))))
    }
    

    FYI: if you are always comparing two strings rather than vectors, you can create a new version that uses max instead of pmax and shave ~25% off the running time:

    mylevsim = function (str1, str2) 
    {
        return(1 - (levenshteinDist(str1, str2)/max(nchar(str1), 
            nchar(str2))))
    }
    > benchmark(mylevsim("applesauce", "aaplesauce"), replications=100000)
                                      test replications elapsed relative user.self
    1 mylevsim("applesauce", "aaplesauce")       100000   5.608        1     4.987
      sys.self user.child sys.child
    1    0.627          0         0
    

    Long story short- there is little difference between adist and levenshteinDist in 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to assign integer to a newly created row: INSERT INTO wcategory (name,
I am trying to assign an function within an function object property without actually
I'm trying to assign a function to the AURenderCallback inputProc int setupRemoteIO(audio unit etc){
I am trying to assign a same size (Width) to all items inside in
I am trying to assign values of my array to function's argument. I can't
I'm trying to assign a function to Object.prototype.equals similar to what's done in Object
I'm trying to assign a method (function) to an ExpandoObject with this signature: public
I am trying to assign a theme based on browser type. I would like
I've been trying to assign a function to onclick event of a dynamically created
I am trying to assign the position of an element like this: <xsl:variable name=offset

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.