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:

```
library(lagged)
v_lagged <- Lagged(0:6) # 1d object
m_lagged <- Lagged(matrix(1:12, nrow = 4)) # 2d object
a_lagged <- Lagged(array(1:24, dim = c(4,3,2))) # 3d object
```

It recognises also `"acf"`

objects from base R time series functions:

The maximal lag stored in the object can be obtained with `maxLag()`

:

The length of the objects is equal to `maxlag(object) + 1`

.

Subsetting with `"["`

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 `x[[0] ]`

.