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 an
Here is a function in base R. I added a check for vectors of equal length as inputs. You could change this logic if desired.
strSim <- function(v1, v2) {
if(length(v1) == length(v2)) 1 - (adist(v1, v2) / pmax(nchar(v1), nchar(v2)))
else stop("vector lengths not equal")}
this returns
strSim("abc", "abcd")
[,1]
[1,] 0.75