title: diff operation within a group, after a dplyr::group_by()
body: <p>Let's say I have this data.frame (with 3 variables)</p>
  
  <pre><code>ID  Period  Score
  123 2013    146
  123 2014    133
  23  2013    150
  456 2013    205
  456 2014    219
  456 2015    140
  78  2012    192
  78  2013    199
  78  2014    133
  78  2015    170
  </code></pre>
  
  <p>Using dplyr I can group them by ID and filter these ID that appear more than once</p>
  
  <pre><code>data &lt;- data %&gt;% group_by(ID) %&gt;% filter(n() &gt; 1)
  </code></pre>
  
  <p>Now, what I like to achieve is to add a column that is: 
  Difference = Score of Period P - Score of Period P-1
  to get something like this:</p>
  
  <pre><code>ID  Period  Score   Difference
  123 2013    146 
  123 2014    133 -13
  456 2013    205 
  456 2014    219 14
  456 2015    140 -79
  78  2012    192 
  78  2013    199 7
  78  2014    133 -66
  78  2015    170 37
  </code></pre>
  
  <p>It is rather trivial to do this in a spreadsheet, but I have no idea on how I can achieve this in R.<br>
  Thanks for any help or guidance.  </p>