R package ‘lagged’ provides classes and methods for objects, like autocovariances, whose natural indexing starts from zero.
The latest stable version is on CRAN.
The vignette shipping with the package gives illustrative examples.
vignette("Guide_lagged", package = "lagged").
You can install the development version of
lagged from Github:
The package provides several classes with methods for indexing starting from zero. Objects can be created with the function
Lagged(). It returns a suitable Lagged object from a class suitable for the argument:
It recognises also
"acf" objects from base R time series functions:
The maximal lag stored in the object can be obtained with
The length of the objects is equal to
maxlag(object) + 1.
"[" drops the laggedness and returns vector, matrix, or array, depending on the dimension of the object. Subsetting with one index gives the data for the requested lags:
Values beyond the maximal lag are
NA. Dimensions are not dropped if an extent has length one (i.e.
drop = FALSE):
To drop dimensions, use “[[”:
Arithmetic operations and mathematical functions are defined naturally on lagged objects. The shorter one is extended with
NA’s to the length of the longer.
Operations between lagged and base R objects are defined, as well. However, it is an error to do operations between objects whose dimensions do not match, unless the base R object is a scalar, or, more generally, has the size of