To calculate levenshtein distance in R, you can use stringdist() function from stringdist package.The Levenshtein distance is distance between two strings is the minimum number of single-character edits required to turn one word into the other.

The following example shows how you can do it with syntax.

Method: Use stringdist() Function


stringdist(string1, string2, method = "lv")

The following example shows how to calculate levenshtein distance in R.

Use stringdist() Function to Calculate Levenshtein Distance

Let’s see how we can calculate levenshtein distance between strings.

# Load library

# Calculate Levenshtein distance
l <- stringdist('Educate', 'Education', method = 'lv')

# Print Levenshtein distance


[1] 3

As the output shows Levenshtein distance between this two strings is 3.