I have a similar question to the question found here: R, subtract value from previous row, group by (slight modification; see below):
In R, lets say I have this data.
Data
id date value
2380 10/30/12 21.01
2380 10/31/12 22.04
2380 11/1/12 22.65
2380 11/2/12 23.11
20100 10/30/12 35.21
20100 10/31/12 37.07
20100 11/1/12 38.17
20100 11/2/12 38.97
20103 10/30/12 57.98
20103 10/31/12 60.83
And I want to subtract the value from the value of the ID of the same ID. I hope this makes sense. See below :)
id date value diff
2380 10/30/12 21.01 0
2380 10/31/12 22.04 1.03
2380 11/1/12 22.65 1.64
2380 11/2/12 23.11 2.10
20100 10/30/12 35.21 0
20100 10/31/12 37.07 1.86
20100 11/1/12 38.17 2.96
20100 11/2/12 38.97 3.76
20103 10/30/12 57.98 0
20103 10/31/12 60.83 2.85
Thank you for your help!