lagfn: Create lagged versions the variables in data

Description Usage Arguments Value Examples

View source: R/IIWcode.R

Description

Create lagged versions the variables in data

Usage

1
lagfn(data, lagvars, id, time, lagfirst = NA)

Arguments

data

The data to be lagged

lagvars

The names of the columns in the data to be lagged

id

A character indicating which column of the data contains subject identifiers. ids are assumed to be consecutive integers, with the first subject having id 1

time

A character indicating which column of the data contains the times at which each of the observations in data was made

lagfirst

The value of the lagged variable for the first time within each subject. This is helpful if, for example, time is the variable to be lagged and you know that all subjects entered the study at time zero

Value

The original data frame with lagged variables added on as columns. For example, if the data frame contains a variable named x giving the value of x for each subject i at each visit j, the returned data frame will contain a column named x.lag containing the value of x for subject i at visit j-1. If j is the first visit for subject i, the lagged value is set to NA

Examples

1
2
3
4
5
6
library(nlme)
data(Phenobarb)
head(Phenobarb)

data <- lagfn(Phenobarb,"time","Subject","time")
head(data)

IrregLong documentation built on May 2, 2019, 8:30 a.m.