I need to create a data frame with a minimum Euclidean distance between each row of the data block and all the other rows of the other frame. Both of my data files are large (about 40,000 lines). This is what I could work out so far.
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) sed.dist<-numeric(5) for (i in 1:(length(sed.dist))) { sed.dist[i]<-(sqrt(sum((y[i,1:7] - x[i,1:7])^2))) }
But this only works when i = j. In fact, you need to find the minimum Euclidean distance, looping through each row one after the other (y [1,1: 7], then y [2,1: 7], etc. to i = 5) of the data frame "y" with all the lines "x" dataframe (x [i, 1: 7]). Each time he does this, I need to find the minimum Euclidean distance for each calculation of the row i of the y-data frame and all rows of the data frame x and save it in another data frame.
loops for-loop r euclidean distance
user14845
source share