trimData {simstudy} | R Documentation |
Trim longitudinal data file once an event has occurred
Description
Trim longitudinal data file once an event has occurred
Usage
trimData(dtOld, seqvar, eventvar, idvar = "id")
Arguments
dtOld |
name of data table to be trimmed |
seqvar |
string referencing column that indexes the sequence or period |
eventvar |
string referencing event data column |
idvar |
string referencing id column |
Value
an updated data.table removes all rows following the first event for each individual
Examples
eDef <- defDataAdd(varname = "e", formula = "u==4", dist = "nonrandom")
P <- t(matrix(c(
0.4, 0.3, 0.2, 0.1,
0.0, 0.4, 0.3, 0.3,
0.0, 0.0, 0.5, 0.5,
0.0, 0.0, 0.0, 1.0
),
nrow = 4
))
dp <- genMarkov(
n = 100, transMat = P,
chainLen = 8, id = "id",
pername = "period",
varname = "u"
)
dp <- addColumns(eDef, dp)
dp <- trimData(dp, seqvar = "period", eventvar = "e", idvar = "id")
dp
[Package simstudy version 0.8.1 Index]