The R Project SVN R

Rev

Rev 27497 | Rev 30595 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 r 1
\name{diff}
7782 hornik 2
\alias{diff}
3
\alias{diff.default}
24782 ripley 4
\alias{diff.POSIXt}
28166 ripley 5
\alias{diff.Date}
2 r 6
\title{Lagged Differences}
7782 hornik 7
\description{
8
  Returns suitably lagged and iterated differences.
9
}
2 r 10
\usage{
1368 maechler 11
diff(x, \dots)
25360 ripley 12
 
13
\method{diff}{default}(x, lag = 1, differences = 1, \dots)
14
 
15
\method{diff}{POSIXt}(x, lag = 1, differences = 1, \dots)
28166 ripley 16
 
17
\method{diff}{Date}(x, lag = 1, differences = 1, \dots)
2 r 18
}
19
\arguments{
7782 hornik 20
  \item{x}{a numeric vector or matrix containing the values to be
21
    differenced.}
22
  \item{lag}{an integer indicating which lag to use.}
23
  \item{differences}{an integer indicating the order of the difference.}
15304 hornik 24
  \item{\dots}{further arguments to be passed to or from methods.}
2 r 25
}
7782 hornik 26
\details{
24782 ripley 27
  \code{diff} is a generic function with a default method and ones for
28166 ripley 28
  classes \code{"\link[stats]{ts}"}, \code{"\link{POSIXt}"} and
29
  \code{"\link{Date}"}.
30
 
24782 ripley 31
  \code{\link{NA}}'s propagate.
7782 hornik 32
}
2 r 33
\value{
7782 hornik 34
  If \code{x} is a vector of length \code{n} and \code{differences=1},
35
  then the computed result is equal to the successive differences
17123 maechler 36
  \code{x[(1+lag):n] - x[1:(n-lag)]}.
37
 
7782 hornik 38
  If \code{difference} is larger than one this algorithm is applied
39
  recursively to \code{x}.
40
  Note that the returned value is a vector which is shorter than
41
  \code{x}.
2 r 42
 
7782 hornik 43
  If \code{x} is a matrix then the difference operations are carried out
44
  on each column separately.
2 r 45
}
24300 ripley 46
\references{
47
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
48
  \emph{The New S Language}.
49
  Wadsworth \& Brooks/Cole.
50
}
15304 hornik 51
\seealso{
27497 ripley 52
  \code{\link[stats]{diff.ts}}, \code{\link[stats]{diffinv}}.
15304 hornik 53
}
2 r 54
\examples{
55
diff(1:10, 2)
56
diff(1:10, 2, 2)
17123 maechler 57
x <- cumsum(cumsum(1:10))
23013 ripley 58
diff(x, lag = 2)
59
diff(x, differences = 2)
24782 ripley 60
 
61
diff(.leap.seconds)
2 r 62
}
286 maechler 63
\keyword{ts}
64
\keyword{arith}