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
#> Key: <id>
#>         id period     u      e
#>      <int>  <int> <int> <lgcl>
#>   1:     1      1     1  FALSE
#>   2:     1      2     2  FALSE
#>   3:     1      3     2  FALSE
#>   4:     1      4     4   TRUE
#>   5:     2      1     1  FALSE
#>  ---                          
#> 448:   100      1     1  FALSE
#> 449:   100      2     1  FALSE
#> 450:   100      3     1  FALSE
#> 451:   100      4     1  FALSE
#> 452:   100      5     4   TRUE