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

时间:2016-10-25 10:02:40

标签: r text-mining agrep

我正在尝试使用agrep R函数匹配字符串。我不明白,为什么它没有返回任何价值。我正在寻找一个解决方案,它将给出给定文本的封闭匹配。在给定的示例中,它应显示"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)

1 个答案:

答案 0 :(得分: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