Trim longitudinal records at an event occurrence
Value
A simulab_sim base data.frame retaining observations through the
requested event, or all observations when it never occurs.
Examples
# A long-form event log: `simulate_until_event()` generates the indicator,
# `trim_events()` then keeps records through its first occurrence.
data <- simulate_until_event(
expand_periods(data.frame(id = 1:20), periods = 10,
id = "id", period = "period"),
definition = define_variable("event", formula = "0.25",
distribution = "binary"),
seed = 1
)
result <- trim_events(
data, id = "id", period = "period", event = "event", occurrence = 1
)
head(result)
#> <simulab_sim:trimmed_events> 6 rows x 4 columns
#> id period time event
#> 1 1 0 0 0
#> 2 1 1 1 0
#> 3 1 2 2 0
#> 4 1 3 3 1
#> 5 2 0 0 0
#> 6 2 1 1 0