Tidy per-actor endpoint summary of a wide-format sequence dataset
Source:R/sequence_terminal.R
actor_endpoints.RdFor each actor (row), reports the first and last observed states,
the time indices at which they appear, the number of observed
steps, and a dropped_out flag that is TRUE when the actor
has a terminal-NA pattern (after the final observed step,
every remaining cell is NA).
Arguments
- data
A wide-format matrix or data.frame where rows are actors and columns are time steps. Cells are state labels;
NArepresents missing observations. Ifdatais adata.frame, non-character/-factor columns (e.g. anidcolumn) are dropped via thecolsargument.- cols
Optional character vector of state-column names. If
NULL(default) every column is treated as a state column.
Value
A tidy data.frame with one row per actor and columns:
actorRow number (or row name if present).
first_stateFirst non-NA state.
last_stateLast non-NA state.
first_stepColumn index of the first observed state.
last_stepColumn index of the last observed state.
n_observedNumber of non-NA cells.
dropped_outTRUEiff every cell afterlast_stepisNAandlast_step < ncol(data).
Examples
actor_endpoints(trajectories) |> head()
#> actor first_state last_state first_step last_step n_observed dropped_out
#> 1 1 Active Active 1 12 12 TRUE
#> 2 2 Average Average 1 15 15 FALSE
#> 3 3 Average Active 1 15 15 FALSE
#> 4 4 Active Average 1 15 15 FALSE
#> 5 5 Active Average 1 15 15 FALSE
#> 6 6 Average Average 1 15 15 FALSE