Find K nearest neighbors, starting from a distance matrix
Try to use FastKNN CRAN package (although it is not well documented). It offers k.nearest.neighbors function where an arbitrary distance matrix can be given. Below you have an example that computes the matrix you need. # arbitrary data train <- matrix(sample(c(“a”,”b”,”c”),12,replace=TRUE), ncol=2) # n x 2 n = dim(train)[1] distMatrix <- matrix(runif(n^2,0,1),ncol=n) # n x … Read more