Is there a more efficient way to achieve the following?
library(dplyr)
filers <- sapply(1:100, function(z) sample(letters, sample(1:20, 1), replace=T) %>% paste(collapse='')) %>% unlist() %>% unname()
n <- length(unique(filers))
similarityMatrix <- matrix(0, nr=n, nc=n)
for (i in 1:n) {
for (j in 1:n) {
similarityMatrix[i, j] <- compare_strings(filers[i], filers[j])
}
}
Note: compare_strings
is pseudo-code for the sake of implying the type of operation I'm trying to perform. Per the comments below, there was some confusion with the prior form of the question because stringdist comes with the function stringdistmatrix
. My scenario involves a function that does not have that option and thus the question has been modified to reflect comments below.