title: Calculate distances between XY coordinates in two different datasets in R
body: <p>Consider we have two different datasets:</p>
  
  <pre><code>X1 = c(1,2,4,5,1,3,1)
  Y1 = c(3,5,6,3,1,5,1)
  df1= data.frame(X1,Y1)
  
  X2 = c(2,3,4,3,2,3,2)
  Y2 = c(3,4,2,6,4,3,4)
  df2= data.frame(X2,Y2)
  </code></pre>
  
  <p>These data are represented in this scatterplot:
  <a href="https://i.stack.imgur.com/y0DOz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y0DOz.png" alt="enter image description here"></a></p>
  
  <p>I would like to calculate the distances between the 7 XY coordinates in df1 (black open dots) and the 7 XY coordinates in df2 (red open triangles).</p>
  
  <p>I know how to calculate the distances between the XY coordinates <a href="https://stats.stackexchange.com/questions/327107/distance-between-all-the-dots-in-a-scatterplot-in-r/327110#327110">within a dataset</a> using dist() and cbind(). But I don't know how to do the same but with XY coordinates in two different datasets.</p>
  
  <p>Using two datasets, we would obtain a table composed by 7 columns and 7 rows, filled by the distances among all these coordinates. Column names would be the coordinates in df1 and row names would be coordinates in df2. </p>
  
  <p>How can I get this data frame with all t</p>