How can I calculate values specific to an ID provided on each line?
<p>I have a data table of values that look like this:</p>

<pre><code>Score ID
1.2    1
2.4    1
1.1    1
1.9    1
2.4    2
3.5    2
2.2    2
1.1    3
1.1    3
1.7    3
3.1    3
2.2    3
</code></pre>

<p>And what I really need is to calculate the Change In Score for each ID in a separate column, such that it looks like this:</p>

<pre><code>Score   ID  Changes
1.2     1   
2.4     1   1.2
1.1     1   -1.3
1.9     1   0.8
2.4     2   
3.5     2   1.1
2.2     2   -1.3
1.1     3   
1.1     3   0
1.7     3   0.6
3.1     3   1.4
2.2     3   -0.9
</code></pre>

<p>Notice how each "changes" is calculated by taking the previous score, and subtracting it from the current score: e.g. in the first changes, you get 1.2 by taking  1.2 = 2.4(current score) - 1.2(The previous score)</p>

<p>The problem is that these scores must only pertain to only the scores within the confines of the ID. You can't just iterate over and take the difference of scores. How would I do this? What logic can I use to test to contain "changes" within the same ID? I'm familiar with R or python (or BASH) to do this.</p>