I have an error when I try to set the operations costs in
stringdist
Any ideas why ?
library(stringdist)
seq = rbind(
c('aaa'),
c('aba'),
c('aab'),
c('ccc')
)
This works perfectly (Levensthein distance)
stringdistmatrix(a = seq, b = seq, method = 'lv')
When I want to set the costs (substitution twice the indel)
stringdistmatrix(a = seq, b = seq, method = 'lv', weight = c(1,1,2,0))
I have this error
Error: all(weight > 0) is not TRUE
See
?stringdistmatrix
. Specifically, read what it says by the weights argument. You'll seeWeights must be positive and not exceed 1
. In this case, the error is telling you that one weight is not positive. You have one of the weights set to 0.Once you fix that, you'll still get an error because you have another weight that exceeds 1.
So, you have to fix that, too. Keep the weights positive and not above 1.
For example