View source: R/sequence-encoding-summaries.R
| encode_sequence_data | R Documentation |
Creates a deterministic dictionary and adds integer and labelled state codes to long-format sequence data.
encode_sequence_data(
data,
sequence_id_col,
order_col,
state_col,
duration_col = NULL,
metadata_cols = NULL,
expected_states = NULL,
state_levels = NULL,
prefix = "S",
width = 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. |
state_levels |
Optional atomic vector defining the complete state ordering. When omitted, factor levels are respected; otherwise observed state labels are sorted alphabetically. |
prefix |
Character prefix used for labelled codes. |
width |
Optional positive integer width for the numeric part of each labelled code. The default is determined from the dictionary size. |
The function does not reinterpret states. State codes are transparent identifiers derived from an explicit or deterministic state ordering.
A named list containing:
data: deterministically sorted canonical data with state_index and
state_code;
dictionary: state labels, integer indices, labelled codes, and an
observed-state indicator;
audit, status, and mapping from input validation;
settings: the resolved code prefix and width.
sequences <- data.frame(
id = c("s1", "s1", "s2", "s2"),
position = c(1, 2, 1, 2),
state = c("home", "search", "home", "product")
)
encoded <- encode_sequence_data(
sequences,
sequence_id_col = "id",
order_col = "position",
state_col = "state"
)
encoded$dictionary
encoded$data
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.