What is the most efficient way to make a matrix of lagged variables in R for an arbitrary variable (i.e. not a regular time series)
For example:
The running function in the gtools package does more or less what you want:
running
gtools
> require("gtools") > running(1:4, fun=I, width=3, allow.fewer=TRUE) $`1:1` [1] 1 $`1:2` [1] 1 2 $`1:3` [1] 1 2 3 $`2:4` [1] 2 3 4