Search code examples
redit-distancestringdist

Maintaining headers in edit distance


I am running edit distance using stringdist. The output replaces the input with a numbered list instead of the actual string being compared. This is currently what I have:

library(stringdist)

a <- c("foo", "bar", "bear", "boat", method = "lv")
stringdistmatrix(a)

1 2 3
2 3    
3 4 1  
4 3 2 2

I would like the output to look like the following so that I can see where the edit distance comes from.

foo bar bear
bar 3    
bear 4 1  
boat 3 2 2

Solution

  • There is the useNames parameter you can specify:

    stringdistmatrix(a, useNames = TRUE)
    
    #     foo bar bear
    #bar    3         
    #bear   4   1     
    #boat   3   2    2