title: R - Apply dist function to groups
body: <p>I am trying to apply <a href="https://www.rdocumentation.org/packages/proxy/versions/0.4-17/topics/dist" rel="nofollow noreferrer">the dist() function</a> row wise in R but the result I get is as if it isn't grouping at all, it is simply applying dist() to all of my dataframe.</p>
  
  <pre><code>df2 %&gt;% dplyr::group_by(X1) %&gt;% dist()
  </code></pre>
  
  <p>Where <code>df2</code> is my dataframe and I am just applying to the head for now, for simplicity. Essentially, each group contains coordinates (A,B) and I am trying to get the distance between each point.</p>
  
  <p>Here is my dataframe:</p>
  
  <pre><code>   X1  A              B
  1   1  12             0.0
  2   1  18             0.0
  3   1  18             1.0
  4   1  13             0.0
  5   1  18             4.0
  6   1  18             0.0
  7   1  18             5.0
  8   1  18             0.0
  9   1  18             0.0
  10  2  73            -2.0
  11  2  73            -0.5
  12  2  74            -0.5
  13  2  73             0.0
  14  2  71            -1.0
  15  2  75             0.0
  </code></pre>
  
  <p>My desired output is the lower triangular matrix of each group, here is an example:
  <a href="https://i.stack.imgur.com/YL4Z5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YL4Z5.png" alt="enter image description here"></a></p>