| lagmatrix | R Documentation |
Find a shifted version of a matrix, adjusting the time base backward (lagged) or forward (leading) by a specified number of observations for each column.
lagmatrix(x, lag)
x |
A matrix or a multivariate time series. |
lag |
A vector of finite integer lags (positive values) or leads
(negative values) with a length equal to the number of columns of
|
A matrix with the same class and size as x.
cvforecast, which uses this function to align the
forecasts and the forecast errors by horizon.
set.seed(1)
x <- matrix(rnorm(20), nrow = 5, ncol = 4)
# Create lags of a matrix
lagmatrix(x, c(0, 1, 2, 3))
# Create leads of a matrix
lagmatrix(x, c(0, -1, -2, -3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.