| 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 multivariate time series. |
lag |
A vector of 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.
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.