The R Project SVN R

Rev

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

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