I've tried out this solution for Hierarchical clustering based on Levenshtein distance as mentioned in this answer: https://stackoverflow.com/a/21513338/14485257
The code for the same is as follows:
set.seed(1)
rstr <- function(n,k){ # vector of n random char(k) strings
sapply(1:n,function(i){do.call(paste0,as.list(sample(letters,k,replace=T)))})
}
str<- c(paste0("aa",rstr(10,3)),paste0("bb",rstr(10,3)),paste0("cc",rstr(10,3)))
# Levenshtein Distance
d <- adist(str)
rownames(d) <- str
hc <- hclust(as.dist(d))
plot(hc)
rect.hclust(hc,k=3)
df <- data.frame(str,cutree(hc,k=3))
In this example, there are 30 strings being clustered and this solution works perfectly fine. But when I apply this same code for anything more than 15,000 strings I get an error looking something like this:
Error: cannot allocate vector of size 74.5 Gb
The total no. of strings that I need to cluster is actually around 500,000. So, is there any way around for solving this issue?