For the function diff
in base package of R,
the parameter lag means the difference between which 2 element,
the default value is 1.
If lag=2
, the difference will be calculated between the 3rd and 1st
(5-1
below), the 4th and the 2nd (8-3
), etc.
The parameter differences is how many time the differences is calculated.
The default value is 1.
If differences=2
, there will be one more difference calculation on
the first difference result (2 2 3 4 75
below):
> inputs <- c(1,3,5,8,12,87)
> diff(inputs)
[1] 2 2 3 4 75
> diff(inputs, lag = 2)
[1] 4 5 7 79
> diff(inputs, differences = 2)
[1] 0 1 1 71
Ref: "What does the diff() function in R do?" on SO.