powered by
Suppose you have longitudinal response y and it's subject id. This function generates lagged y for each subject.
ylag(id,y,lag,na=FALSE)
subject id
response
how many lags for y
logical; whether remain NAs in the response when lag \(>1\). Default to FALSE and output 0s instead of NAs.
return a vector of lagged y
# NOT RUN { id <- rep(c(1:20),each=3) y <- rnorm(length(id)) ylag(id,y,1) #lag=1 ylag(id,y,2,na=FALSE) #lag=2 # }
Run the code above in your browser using DataLab