View source: R/sequence-encoding-summaries.R
| summarise_sequence_transitions | R Documentation |
Counts transitions between adjacent ordered states for each sequence and across the complete data set.
summarise_sequence_transitions(
data,
sequence_id_col,
order_col,
state_col,
metadata_cols = NULL,
expected_states = NULL,
include_self = TRUE
)
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. |
metadata_cols |
Optional character vector naming columns that should remain constant within each sequence. |
expected_states |
Optional vector of known or permitted state values. |
include_self |
Logical value indicating whether transitions from a state to the same state should be included. |
A transition is defined only between adjacent rows after deterministic ordering by sequence identifier, sequence order, and original row. Sequences with one state contribute no transitions.
A named list containing:
by_sequence: transition counts, proportions within each sequence, and
conditional proportions within each origin state;
overall: transition counts, sequence coverage, global proportions, and
conditional origin-state proportions;
audit, status, mapping, and the resolved include_self setting.
sequences <- data.frame(
id = c("s1", "s1", "s1", "s2", "s2"),
position = c(1, 2, 3, 1, 2),
state = c("A", "B", "C", "A", "C")
)
transitions <- summarise_sequence_transitions(
sequences,
sequence_id_col = "id",
order_col = "position",
state_col = "state"
)
transitions$by_sequence
transitions$overall
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.