I have a data frame formatted like so:
| GameId | Eval |
|---|---|
| 1 | 1.00 |
| 1 | 1.50 |
| 1 | 0.50 |
| 2 | -1.00 |
| 2 | 2.00 |
| 2 | 1.00 |
| 3 | 1.50 |
| 3 | -0.50 |
I would like a new column which accounts for differences between the current row and the previous, but resets at the start of the next GameId so that it looks like so:
| GameId | Eval | Diff |
|---|---|---|
| 1 | 1.00 | NA |
| 1 | 1.50 | 0.50 |
| 1 | 0.50 | -1.00 |
| 2 | -1.00 | NA |
| 2 | 2.00 | 3.00 |
| 2 | 1.00 | -2.00 |
| 3 | 1.50 | NA |
| 3 | -0.50 | -2.00 |