MyNixOS website logo
Description

Classes and Methods for Lagged Objects.

Provides classes and methods for objects, whose indexing naturally starts from zero. Subsetting, indexing and mathematical operations are defined naturally between lagged objects and lagged and base R objects. Recycling is not used, except for singletons. The single bracket operator doesn't drop dimensions by default.

CRANStatusBadge R-CMD-check codecov

R package 'lagged' provides classes and methods for objects, like autocovariances, whose natural indexing starts from zero.

Installing lagged

The latest stable version is on CRAN.

install.packages("lagged")

The vignette shipping with the package gives illustrative examples. vignette("Guide_lagged", package = "lagged").

You can install the development version of lagged from Github:

library(devtools)
install_github("GeoBosh/lagged")

Overview

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:

ap_lagged <- Lagged(acf(AirPassengers, plot = FALSE))

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

maxLag(v_lagged)
maxLag(m_lagged)
maxLag(a_lagged)

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

length(v_lagged)
length(m_lagged)
length(a_lagged)

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:

tmp <- v_lagged[0:2]
tmp <- m_lagged[0:2]
tmp <- a_lagged[0:1]

Values beyond the maximal lag are NA. Dimensions are not dropped if an extent has length one (i.e. drop = FALSE):

v_lagged[0]
m_lagged[0]
a_lagged[0]

To drop dimensions, use "[[":

v_lagged[[0]]
m_lagged[[0]]
a_lagged[[0]]

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] ].

Metadata

Version

0.3.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows