Mark leading-NA cells with an explicit state label
Source:R/sequence_terminal.R
mark_first_state.Rdmark_first_state() fills every missing cell before each sequence's
first observed state with an explicit state, "Start" by default, and
returns the wide table. It is the counterpart of mark_terminal_state()
for left-censored data, such as students who join a course at
different times: a network built from the result shows into
which states the late entrants arrive. Internal and trailing missing
cells are left as they are, and so are rows observed from the first
position or not at all.
The marked state is a transient entry point, not an absorbing state: once a sequence leaves it, it never returns. In a transition network built from the result, its row holds the moves from it, which go to the first observed states and, for sequences with two or more leading missing cells, back to itself.
Arguments
- data
The sequences: a matrix or data frame with one row per actor and one column per position, holding state labels, with
NAfor a missing observation. Withoutcols, the frame must be one column or a numbered run of positions (T1,T2, ...); other columns beside them raise an error of classnestimate_bad_input.- state
The label written into the leading missing cells, a single non-empty string. Default
"Start". If the label already occurs indata, a warning of classnestimate_state_collisionis given and_1,_2, ... is appended until it is unique, so the marker is never confused with an observed state.- cols
The columns holding the positions, in order; only they are returned. A name not in
dataraises an error of classnestimate_bad_input. DefaultNULL(every column).
Value
A data frame of character columns with the shape of data (or of
its cols), the leading missing cells filled with the marker. The label
used is kept in the "leading_state" attribute, which differs from
state when it had to be made unique. The columns are marked as
positions, so build_network() reads them without state_cols.