Learn R Programming

wgeesel (version 1.5)

ylag: Generate subject-level lagged response

Description

Suppose you have longitudinal response y and it's subject id. This function generates lagged y for each subject.

Usage

ylag(id,y,lag,na=FALSE)

Arguments

id

subject id

y

response

lag

how many lags for y

na

logical; whether remain NAs in the response when lag \(>1\). Default to FALSE and output 0s instead of NAs.

Value

return a vector of lagged y

Examples

Run this code
# 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