[R] weird behavior of DoubleMetaphone

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Wed Dec 14 20:35:06 CET 2016


I was wondering if anyone can answer this question.

library(PGRdup)

Both lines below return "NTFL".
DoubleMetaphone("netflix")$primary
DoubleMetaphone("net flex")$primary

Now, I modify the function a bit - I first split the string on
"space", then merge back together:

mymetaphone = function(x){
    temp <- strsplit(x, split=" ")[[1]]
    for(word in 1:length(temp)){
     temp[word]<-DoubleMetaphone(temp[word])$primary
    }
    return(paste(temp, collapse = ""))
}
mymetaphone("netflix")    # returns "NTFL"
mymetaphone("net flex")  # returns "NTFLKS"

Why such a difference between DoubleMetaphone("net flex")$primary and
mymetaphone("net flex")?
Why isn't DoubleMetaphone("net flex")$primary returning "NTFLKS"?
Thank you!

-- 
Dimitri Liakhovitski



More information about the R-help mailing list