Create a Lagged Time Series

DESCRIPTION:

Returns a time series like the input but shifted in time.

USAGE:

lag(x, k=1)

REQUIRED ARGUMENTS:

x
a univariate or multivariate regular time series. Missing values ( NAs) are allowed.

OPTIONAL ARGUMENTS:

k
the number of positions the new series is to lead the input series, i.e., the resulting series is shifted backwards in time; negative values lag the series forwards in time. Non-integer, values of k are rounded to the nearest integer.

VALUE:

a time series of the same length and the same number of channels as x but lagged by k positions. Only the start and end dates are changed; the series still has the same number of observations.

NOTE:

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.

DETAILS:

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.

SEE ALSO:

, , , , .

EXAMPLES:

lag12co2 <- lag(co2, 12) # co2 lagged by 12 months
ts.intersect(co2, lag(co2, 12))