lag(x, k=1)
NA
s) are allowed.
k
are rounded
to the nearest integer.
x
but lagged by
k
positions.
Only the start and end dates are changed;
the series still has the same number of observations.
Logically
k
should have the opposite sign,
but due to its pervasive use in other functions,
lag
remains unchanged.
However, the new
shift
function
(which calls
lag
by default)
has the more logical convention.
A similar function
seriesLag
computes a lagged/led series that
has the same time position and but shifted data slot.
Use
ts.intersect
or
ts.union
to align
the time domains of several series
(using
cbind
on lagged series
will not align their domains).
lag
is defined for
both regular (
rts
)
and calendar (
cts
) time series.
To create a lagged/led series for SV4 "timeSeries" or "signalSeries" objects,
use
seriesLag
or
shift
.
lag12co2 <- lag(co2, 12) # co2 lagged by 12 months ts.intersect(co2, lag(co2, 12))