df:
ID cat1
A0001 358
A0001 279
A0049 324
A0049 358
A0049 432
To calculate the difference in value in cat1 between the repeated measures (by ID). The expected output df should look like:
ID cat1 cat1_diff
A0001 358 NA
A0001 279 -79
A0049 324 NA
A0049 358 26
A0049 432 74
I would appreciate any insights how to do this in R.