0

I am trying to match string using agrep function of R. I do not understand, why it's not returning any value. I am looking a solution which will give closed match of the given text. In the given example it should show "ms sharda stone crusher prop rupa"

I would appreciate any kind of help. Thanks in advance.

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)
honey
  • 89
  • 2
  • 8
  • because you're trying to match the whole expression `"ms sharda stone crusher prop rupa"`, try `agrep("rupa",x,ignore.case=T,value=T,max.distance = 0.1, useBytes = FALSE) ` why are you using `agrep` and not `grep` ? – timat Oct 25 '16 at 10:17
  • But I am looking for the method which matches whole expression. Is there a way to do that? Thank you! – honey Oct 25 '16 at 10:19
  • So it is returning no value.. as the whole expression is not contains in your vector.. show the output you're looking for... (by editing your response) – timat Oct 25 '16 at 10:21
  • Sorry for the confusion, edited me question. I want to get the closest match of the given expression. – honey Oct 25 '16 at 10:55

1 Answers1

0

It is because of your max.distance parameter. see ?agrep.

for instance:

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" 

If you want only the closest match see: best match

Community
  • 1
  • 1
timat
  • 1,480
  • 13
  • 17