title: how to calculate the difference(s) between repeated measures in R
body: <p>df as follows:</p>
  
  <pre><code>ID     cat1
  A0001   358
  A0001   279
  A0008   422
  A0008   433
  A0049   324
  A0049   358
  A0049   432
  </code></pre>
  
  <p>I wanted to calculate the difference in value in cat1 between the repeated measures (by unique ID). </p>
  
  <p>The expected output should look like:</p>
  
  <pre><code> ID    cat1 cat1_diff
  A0001   358   NA
  A0001   279   -79
  A0008   422   NA
  A0008   433   11
  A0049   324   NA
  A0049   358   26
  A0049   432   74
  </code></pre>
  
  <p>Would appreciate any help.</p>