[R] Calculating column differences
Jeff Reichman
re|chm@nj @end|ng |rom @bcg|ob@|@net
Wed Mar 24 17:48:31 CET 2021
r-help forum
I'm trying to calculate the diff between two rows and them mutate the
difference into a new column. I'm using the diff function but not giving me
what I want.
df <- data.frame(ID=1:5,Score=4*2:6)
What a want where
ID Score diff
1 1 8 8
2 2 12 4
3 3 16 4
4 4 20 4
5 5 24 4
What I am getting
ID Score diff
1 1 8 NA
2 2 12 4
3 3 16 4
4 4 20 4
5 5 24 4
Jeff
[[alternative HTML version deleted]]
More information about the R-help
mailing list