I have generated 5 coordinates (each consisting of an x and a y variable, which are considered the "truth."
D <- 2 #amount of dimensions
K <- 5
events <- 2*K #number of events
truth <- matrix(data=runif(events, min = 0, max = 1), nrow=K)
E <- 2
test <- matrix(data=runif(2*E, min = 0, max = 1), nrow=E)
If you want to avoid having to calculate the distance for every row combination, avoid using the base
dist, and do it without any external packages, you can manually code a Euclidean distance by making two conforming matrices first.
diffs <- truth[rep(1:nrow(truth), nrow(test)),] -test[rep(1:nrow(test), each=nrow(truth)),] eucdiff <- function(x) sqrt(rowSums(x^2)) max.col(-matrix(eucdiff(diffs), nrow=nrow(test), byrow=TRUE), "first") # 4 3
Using @aichao's data above.