View source: R/sequence-encoding-summaries.R
| summarise_sequence_states | R Documentation |
Produces per-sequence and overall state-frequency summaries from validated ordered sequence data.
summarise_sequence_states(
data,
sequence_id_col,
order_col,
state_col,
duration_col = NULL,
metadata_cols = NULL,
expected_states = NULL
)
data |
A data frame containing ordered state observations. |
sequence_id_col |
Name of the sequence identifier column. |
order_col |
Name of the numeric sequence-order column. |
state_col |
Name of the categorical state column. |
duration_col |
Optional name of a numeric duration column. |
metadata_cols |
Optional character vector naming columns that should remain constant within each sequence. |
expected_states |
Optional vector of known or permitted state values. |
Observation proportions use state rows as the denominator. Sequence
proportions report the proportion of sequences in which each state occurs.
Missing durations are excluded from duration calculations; an all-missing
duration group returns NA.
A named list containing:
by_sequence: state counts and proportions within each sequence;
overall: state counts and proportions across all sequences;
audit, status, and mapping from input validation.
When duration_col is supplied, both tables also include duration sums,
duration proportions, and mean durations.
sequences <- data.frame(
id = c("s1", "s1", "s1", "s2", "s2"),
position = c(1, 2, 3, 1, 2),
state = c("A", "B", "A", "B", "C")
)
summaries <- summarise_sequence_states(
sequences,
sequence_id_col = "id",
order_col = "position",
state_col = "state"
)
summaries$by_sequence
summaries$overall
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.