.BG
.VE $Header: /usr/s/current/s/.help/RCS/diff,v 1.3 87/12/08 14:40:45 rab Exp $
.FN diff
.TL
diff: Create a Differenced Series
.CS
diff(x, lag, diff)
.PP
.AG x
a time-series or vector.  Missing values (NAs) are allowed.
.AG lag
the lag of the difference to be computed (default is 1).
.AG diff
the number of differences to be done (default is 1).
.PP
.RT
a time-series which is the `diff'th difference of lag `lag' for `x'.
For first differences where `y <- diff(x,k)', `y[i]' is `x[i] \- x[i\-k]',
and `len(y)' is `len(x) \- k'.
To construct an `n'th difference, this procedure is iterated `n' times.
Any operation on an NA produces an NA.
.PP
.EX
d2x <- diff(x,1,2)   # second difference of lag 1

diff(range(x))  # max(x) \- min(x)
.PP
The start date of `d2x' will be 2 periods later than `x' due to the
differencing.
.KW ts*
.KW math
.WR
