diff.Rd 1.8 KB
Newer Older
 Radford Neal committed May 18, 2013 1 2 % File src/library/base/man/diff.Rd % Part of the R package, http://www.R-project.org  Radford Neal committed Aug 26, 2016 3 % Copyright 1995-2011 R Core Team  Radford Neal committed May 18, 2013 4 5 6 7 8 9 10 % Distributed under GPL 2 or later \name{diff} \alias{diff} \alias{diff.default} \alias{diff.POSIXt} \alias{diff.Date}  Radford Neal committed May 18, 2013 11 \concept{difference}  Radford Neal committed May 18, 2013 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \title{Lagged Differences} \description{ Returns suitably lagged and iterated differences. } \usage{ diff(x, \dots) \method{diff}{default}(x, lag = 1, differences = 1, \dots) \method{diff}{POSIXt}(x, lag = 1, differences = 1, \dots) \method{diff}{Date}(x, lag = 1, differences = 1, \dots) } \arguments{ \item{x}{a numeric vector or matrix containing the values to be differenced.} \item{lag}{an integer indicating which lag to use.} \item{differences}{an integer indicating the order of the difference.} \item{\dots}{further arguments to be passed to or from methods.} } \details{ \code{diff} is a generic function with a default method and ones for classes \code{"\link{ts}"}, \code{"\link{POSIXt}"} and \code{"\link{Date}"}. \code{\link{NA}}'s propagate. } \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+lag):n] - x[1:(n-lag)]}. 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. } \references{ Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) \emph{The New S Language}. Wadsworth & Brooks/Cole. } \seealso{ \code{\link{diff.ts}}, \code{\link{diffinv}}. } \examples{ diff(1:10, 2) diff(1:10, 2, 2) x <- cumsum(cumsum(1:10)) diff(x, lag = 2) diff(x, differences = 2) diff(.leap.seconds) } \keyword{arith}