panel_lag: Lag each symbol column by k steps

View source: R/ml.R

panel_lagR Documentation

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)

Arguments

df

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

k

Integer lag (>= 1).

Value

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

Examples

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

PortfolioTesteR documentation built on Nov. 5, 2025, 5:23 p.m.