Skip to content
Prev 313386 / 398502 Next

How do you use agrep inside a loop

Hello,

See if this is it. You must reinitialize 'result_vector' just before the 
loop that constructs it.


test1 <- c("Vashi", "Vashi,navi Mumbai", "Thane", "Vashi,new Mumbai",
         "Thana", "Surekha", "Thane(w)", "surekhaN")

result <- vector("list", (length(test1)-1))
for(i in 1:(length(test1)-1)){
     result_vector <- vector()
     for(j in (i+1):length(test1)){
         tmp <- agrep(test1[i], test1[j],
                     ignore.case = TRUE, value = TRUE,
                     max.distance = 0.1)
         if(length(tmp) > 0) result_vector[j-i] <- tmp
     }
     result[[i]] <- result_vector
}
result


Hope this helps,

Rui Barradas
Em 11-12-2012 11:23, surekha nagabhushan escreveu: