I have 2 data sets of cells (each set has multiple rows (individual cells) with x,y coordinates as columns) I want to find the smallest distance for every cell in data set A to any cell in data set B.
examples DSA = 0,0 0,1 1,0 DSB set B = 2,2
to find distance (d) from cells in A to B I did this
ax <- DS1$X
ay <- DS1$Y
bx <- DS2$X
by <- DS2$Y
D <- c(sqrt((ax-bx)^2 + (ay-by)^2))
D
[1] 2.828427 2.236068 2.236068
So it did give me what I needed, however I am having problems if not DSB has multiple points
Do I need to added a loop so that it tries all DSA values by all BSB values?
As it stands it will do the first point in DSA by only the first point in DSB, then the second value of DSA by only the second values of DSB. I want it to do the first value of DSA by all values of DSB and then return only the smallest of those 2 numbers and keep repeating through all values of DSA.