Code:
library(dplyr)
BOD
Output:
Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
Code:
mutate(BOD, change = demand - lag(demand))
Output:
Time demand change
1 1 8.3 NA
2 2 10.3 2.0
3 3 19.0 8.7
4 4 16.0 -3.0
5 5 15.6 -0.4
6 7 19.8 4.2