Learn R Programming

PortfolioTesteR (version 0.1.4)

panel_lag: Lag each symbol column by k steps

Description

Given a wide panel with a Date column followed by symbol columns, returns the same shape with each symbol column lagged by k periods. The Date column is preserved; leading values introduced by the lag are NA_real_.

Usage

panel_lag(df, k = 1L)

Value

A data.table with the same columns as df, lagged by k.

Arguments

df

data.frame or data.table with columns Date then symbols.

k

Integer lag (>= 1).

Examples

Run this code
x <- data.frame(Date = as.Date("2020-01-01") + 0:2, A = 1:3, B = 11:13)
panel_lag(x, 1L)

Run the code above in your browser using DataLab