R 的 agrep 函数不适用于文本匹配

agrep function of R is not working for text matching

我正在尝试使用 Ragrep 函数来匹配字符串。我不明白,为什么它没有返回任何值。我正在寻找一个解决方案,它将给出给定文本的封闭匹配。在给定的示例中,它应该显示 "ms sharda stone crusher prop rupa"

如有任何帮助,我将不胜感激。 提前致谢。

x= as.vector(c("sharda stone crusher prop roopa","sharda stone crusher prop rupa"))
agrep("ms sharda stone crusher prop rupa devi",x,ignore.case=T,value=T,max.distance = 0.1, useBytes = FALSE)
character(0)

是因为你的max.distance参数。参见 ?agrep

例如:

agrep("ms sharda stone crusher prop rupa devi",x,ignore.case=T,value=T,max.distance = 0.2, useBytes = FALSE)
"sharda stone crusher prop rupa"
agrep("ms sharda stone crusher prop rupa devi",x,ignore.case=T,value=T,max.distance = 0.25, useBytes = FALSE)
"sharda stone crusher prop roopa" "sharda stone crusher prop rupa" 
agrep("ms sharda stone crusher prop rupa devi",x,ignore.case=T,value=T,max.distance = 9, useBytes = FALSE)
"sharda stone crusher prop rupa"
agrep("ms sharda stone crusher prop rupa devi",x,ignore.case=T,value=T,max.distance = 10, useBytes = FALSE)
"sharda stone crusher prop roopa" "sharda stone crusher prop rupa" 

如果您只想要最接近的匹配项,请参阅: best match