diff(x, lag=1, differences=1)
bdTimeSeries
object, a
bdSignalSeries
object, a vector, a
bdTimeDate
object, a
bdTimeSpan
object, or a matrix.
Missing values (
NA
s) are allowed.
bdTimeDate
object, a
bdTimeSpan
object, a matrix, a time series, a
bdTimeSeries
object, or a
bdSignalSeries
object that is the
n
th
difference of lag
k
for
x
.
If y <- diff(x,k),
y[i]
is
x[i]-x[i-k]
,
and
length(y)
is
length(x)-k
. In a time series or
bdTimeSeries
, the first
k
times are dropped.
To construct an
n
th difference, the procedure is iterated
n
times.
This is a generic function. Methods exist for the time series
classes
"rts"
, and
"cts"
and for objects of class
"dates"
.
Any operation on an
NA
produces an
NA
.
For matrices, the differences are performed on each column separately.
# second difference of lag 4: # the start date of d2x will be # 8 periods later than x freeny.rts<- as.rts(freeny.y) freeny.df2 <- diff(freeny.rts, 1,2) # 10th difference of an alternating series diff(rep(c(-1,1),10), 1, 10) [1] -1024 1024 -1024 1024 -1024 1024 -1024 1024 [9] -1024 1024 diff(range(x)) # max(x) - min(x)