\Header{diff}{Lagged Differences}
\methalias{diff.default}{diff}
\keyword{ts}{diff}
\keyword{arith}{diff}
\begin{Description}\relax
Returns suitably lagged and iterated differences.\end{Description}
\begin{Usage}
\begin{verbatim}
diff(x, ...)
diff.default(x, lag=1, differences=1)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a numeric vector or matrix containing the values to be
differenced.
\item[\code{lag}] an integer indicating which lag to use.
\item[\code{differences}] an integer indicating the order of the difference.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{NA}'s propagate.\end{Details}
\begin{Value}
If \code{x} is a vector of length \code{n} and \code{differences=1},
then the computed result is equal to the successive differences
\code{x[(1:n-lag)] - x[(lag:n)]}.
If \code{difference} is larger than one this algorithm is applied
recursively to \code{x}.
Note that the returned value is a vector which is shorter than
\code{x}.

If \code{x} is a matrix then the difference operations are carried out
on each column separately.\end{Value}
\begin{Examples}
\begin{ExampleCode}
diff(1:10, 2)
diff(1:10, 2, 2)
\end{ExampleCode}
\end{Examples}

