I'm trying to match a string to a vector of strings:
a <- c('abcde', 'abcdf', 'abcdg')
agrep('abcdh', a, max.distance=list(substitutions=1))
# [1] 1 2 3
agrep('abchh', a, max.distance=list(substitutions=2))
# character(0)
I didn't expect the latter result as substituting two characters from
the pattern makes the pattern identical to the vector elements. This does, however, work with all
instead of substitutions
:
agrep('abchh', a, max.distance=list(all=2))
# [1] 1 2 3
What do I need to change to match with more than 1 substitution allowed? Is substitution
just a broken option? Thanks.
Note: this question is essentially the same as this one: https://stat.ethz.ch/pipermail/r-help/2011-June/281731.html, but that was never answered.