View source: R/data_conversion.R
| wide_to_long | R Documentation |
Convert sequence data from wide format (one row per sequence, columns as time points) to long format (one row per action).
wide_to_long(
data,
id_col = NULL,
time_prefix = "V",
action_col = "Action",
time_col = "Time",
drop_na = TRUE
)
data |
Data frame in wide format with sequences in rows. |
id_col |
Character. Name of the ID column, or NULL to auto-generate IDs. Default: NULL. |
time_prefix |
Character. Prefix for time point columns (e.g., "V" for V1, V2, ...). Default: "V". |
action_col |
Character. Name of the action column in output. Default: "Action". |
time_col |
Character. Name of the time column in output. Default: "Time". |
drop_na |
Logical. Whether to drop NA values. Default: TRUE. |
This function converts data from the format produced by simulate_sequences()
to the long format used by many TNA functions and analyses.
A data frame in long format with columns:
Sequence identifier (integer).
Time point within the sequence (integer).
The action/state at that time point (character).
Any additional columns from the original data are preserved.
long_to_wide for the reverse conversion,
prepare_for_tna for preparing data for TNA analysis.
wide_data <- data.frame(
V1 = c("A", "B", "C"), V2 = c("B", "C", "A"), V3 = c("C", "A", "B")
)
long_data <- wide_to_long(wide_data)
head(long_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.