# NOT RUN {
## create a dataset with dates
df <- data.frame(
hospid = 1:100,
docid = round(runif(100, 1, 10)),
dis_date = formatDate(runif(100, 42700, 42800))
)
## lagged dis_date, not specifed "by"
lagRows(df, dis_date)
## lagged dis_date by docid
## first we need to sort
df1 <- arrange(df, docid)
df1
lagRows(df1, dis_date, by = docid, lag_var = "lag_date")
# }
Run the code above in your browser using DataLab