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

Description Usage Arguments Details Value Examples

View source: R/rutils.R

Description

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

Usage

1
diff_it(in_put, lagg = 1, ...)

Arguments

in_put

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 diff_it() 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 diff_it() 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

1
2
3
4
5
6
# Diff vector by 2 periods
rutils::diff_it(1:10, lagg=2)
# Diff matrix by negative 2 periods
rutils::diff_it(matrix(1:10, ncol=2), lagg=-2)
# Diff an xts time series
rutils::diff_it(rutils::etf_env$VTI, lagg=10)

algoquant/rutils documentation built on Feb. 26, 2021, 1:30 a.m.