I want to replace nested for loops with appropriate apply function in R.
I declare a matrix with the following dimensions - ncol is 412 and nrow 2164
dist.name.enh <- matrix(NA, ncol = length(WW_name),nrow = length(Px_name))
The for loops for calculating the string distances are as below
for(i in 1:length(WW_name)) {
for(j in 1:length(Px_name)) {
dist.name.enh[j,i]<-stringdist(tolower(WW_name)[i],
tolower(Px_name)[j],
method = "lv")
}
}
How do I avoid the for loops as it is taking very long to return the matrix.
The code is looked up from R-bloggers website