title: Calculate first difference by group in R
body: <p>I was wondering if someone could help me calculate the first difference of a score by group. I know it should be a simple process but for some reason I'm having trouble doing it..... yikes</p>
  
  <p>Here's an example data frame:</p>
  
  <pre><code>score &lt;- c(10,30,14,20,6)
  
  group &lt;- c(rep(1001,2),rep(1005,3))
  
  df &lt;- data.frame(score,group)
  
  &gt; df 
    score group
  1    10  1001
  2    30  1001
  3    14  1005
  4    20  1005
  5     6  1005
  </code></pre>
  
  <p>And here's the output I was looking for.</p>
  
  <pre><code>1   NA
  2   20
  3   NA  
  4    6
  5  -14
  </code></pre>
  
  <p>Thanks in advance.</p>