title: Nearest Neighbor (distance between coordinate pairs)
body: <p>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.</p>
  
  <p>examples
  DSA = 0,0 0,1 1,0
  DSB set B = 2,2</p>
  
  <p>to find distance (d) from cells in A to B I did this</p>
  
  <pre><code>ax &lt;- DS1$X
  ay &lt;- DS1$Y
  bx &lt;- DS2$X
  by &lt;- DS2$Y
  D &lt;- c(sqrt((ax-bx)^2 + (ay-by)^2))
  D
  [1] 2.828427 2.236068 2.236068
  </code></pre>
  
  <p>So it did give me what I needed, however I am having problems if not DSB has multiple points</p>
  
  <p>Do I need to added a loop so that it tries all DSA values by all BSB values?</p>
  
  <p>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.</p>