Trim longitudinal data file once an event has occurred

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
#> id period u e #> 1: 1 1 1 FALSE #> 2: 1 2 4 TRUE #> 3: 2 1 1 FALSE #> 4: 2 2 3 FALSE #> 5: 2 3 3 FALSE #> --- #> 433: 99 2 3 FALSE #> 434: 99 3 3 FALSE #> 435: 99 4 4 TRUE #> 436: 100 1 1 FALSE #> 437: 100 2 4 TRUE