I was wondering if someone could help me calculate the first difference of a score by group. I know it should be a simple process but for some reason I'm having trouble doing it..... yikes
Here's an example data frame:
score <- c(10,30,14,20,6)
group <- c(rep(1001,2),rep(1005,3))
df <- data.frame(score,group)
> df
score group
1 10 1001
2 30 1001
3 14 1005
4 20 1005
5 6 1005
And here's the output I was looking for.
1 NA
2 20
3 NA
4 6
5 -14
Thanks in advance.