I have two tables, X and Y, (X is big and Y has 9 rows, of course same columns) and I need to find the minimum euclidean distance between each row of X with each row of Y. I do this and it works:
x<-matrix(c(3,6,3,4,8),nrow=5,ncol=7,byrow = TRUE)
y<-matrix(c(1,4,4,1,9),nrow=5,ncol=7,byrow = TRUE)
unlist(lapply(seq_len(nrow(y)), function(i) min(sqrt(colSums((y[i, ] -t(x))^2))))
Now I need to export which row of Y (1 to 9) is the one for each row, and there is my problem, because I do not know how to face this. Any clue about how to write this? I've been thinking about doing something like:
unlist(lapply(seq_len(nrow(y)), function(i) nrow(min(sqrt(colSums((y[i, ] - t(x))^2)))==T)))
but I cannot make it work.
Thank you!