Skip to contents

lagts and leadts are new generic functions that do intuitive computations of lags and leads. The main purpose is to overcome the confusion about the sign of the lag order in the base lag function that is employed differently by different classes.

Usage

lagts(x, ...)
leadts(x, ...)

# Default S3 method
lagts(x, k = 1, na.pad = TRUE, ...)
# S3 method for class 'ts'
lagts(x, k = 1, na.pad = TRUE, ...)
# S3 method for class 'zoo'
lagts(x, k = 1, na.pad = TRUE, ...)

Arguments

x

an object. The default method works for vectors and matrices.

k

For lag the number of lags (in units of observations). Note the sign of k behaves as employed in most textbooks and not as in lag.

na.pad

logical. If TRUE it adds any times that would not otherwise have been in the result with a value of NA. If FALSE those times are dropped.

...

currently not used.

Details

lagts by default computes real lags for positive k while lag would in fact compute leads. The latter lead to a lot of confusion among users of lag, especially because some time series classes followed the base behavior while others decided for the intuitive (but inconsistent) behavior. lagts aims to overcome this confusions

This functionality is still under development.

Value

The lags or leads of the original object.

See also

Examples

if (FALSE) { # \dontrun{
x <- zoo(11:21)
lag(x, k = 1)
lag(x, k = -1)
lagts(x, k = 1)
lagts(x, k = -1) ## leadts not written yet
} # }