diffit: Calculate the row differences of a _numeric_ or _Boolean_...

View source: R/rutils.R

diffitR Documentation

Calculate the row differences of a numeric or Boolean vector, matrix, or xts time series.

Description

Calculate the row differences of a numeric or Boolean vector, matrix, or xts time series.

Usage

diffit(input, lagg = 1, ...)

Arguments

input

A numeric or Boolean vector or matrix, or xts time series.

lagg

An integer equal to the number of time periods of lag (default is 1).

Details

The function diffit() calculates the row differences between rows that are lagg rows apart. Positive lagg means that the difference is calculated as the current row minus the row that is lagg rows above. (vice versa for a negative lagg). This also applies to vectors, since they can be viewed as single-column matrices. The leading or trailing stub periods are padded with zeros.

When applied to xts time series, the function diffit() calls the function diff.xts() from package xts, but it pads the output with zeros instead of with NAs.

Value

A vector, matrix, or xts time series. with the same dimensions as the input object.

Examples

# Diff vector by 2 periods
rutils::diffit(1:10, lagg=2)
# Diff matrix by negative 2 periods
rutils::diffit(matrix(1:10, ncol=2), lagg=-2)
# Diff an xts time series
rutils::diffit(rutils::etfenv$VTI, lagg=10)

algoquant/rutils documentation built on April 18, 2024, 12:05 a.m.