I am applying a custom function over all combinations from two data sets. Is there a more efficient way to accomplish this?
ptm <- proc.time()
for (i in 1:nrow(x)) {
d <- list()
for (j in 1:nrow(centroids)) {
d[j] <- f_dist(x[i,],centroids[j,])
}
x[i,]$cluster <- which.min(d)
x[i,]$dist_from_centroid <- d[which.min(d)]
}
proc.time()-ptm