agrep working with del, ins arguments

202 views Asked by At

How can "abteam" with "ab" be matched using this code?

agrep("abteam",c("acb","abd","ab"),value=T,ignore.case = TRUE,max = list(del = 10, ins = 10, sub = 10))

The result is character(0), though I specified del=10, ins=10. What is the problem? How does agrep work?

1

There are 1 answers

6
zero323 On BEST ANSWER

From the help file:

If ‘cost’ is not given, ‘all’ defaults to 10%, and the other transformation number bounds default to ‘all’.

As far as I understand it means that either cost or all is a limiting factor even if you set del, ins and sub. If you want to allow 10 transformations you can simply set max = 10. Additional parameters can be used to limit specific transformations, for example:

> x <- c("fooar","ooar","foobaz")
> agrep("foobar", x, value=T, max = list(all = 3, del = 0, ins = 0))
[1] "foobaz"

In your case you could use max = list(all = 10 ,del = 10, ins = 10, sub = 10)).