The problem is the representation.
If we transform it into a zoo time series, z, with one
series per column and one time point per row then we
can just merge the series with its lag.
> DF <- data.frame(id = c(1, 1, 1, 2, 2, 2), time = c(1, 2,
+ 3, 1, 2, 3), value = c(-0.56047565, -0.23017749, 1.5
Hi all.
I'm looking for robust ways of building lagged variables in a dataset
with multiple individuals.
Consider a dataset with variables like the following:
##
set.seed(123)
d <- data.frame(id = rep(1:2, each=3), time=rep(1:3, 2), value=rnorm(6))
##
>d
id time value
1 11 -0.56047565