Convert sequence data from long format (one row per action) to wide format (one row per sequence, columns as time points).
Usage
long_to_wide(
data,
id_col = "Actor",
time_col = "Time",
action_col = "Action",
time_prefix = "V",
fill_na = TRUE
)Arguments
- data
Data frame in long format.
- id_col
Character. Name of the column identifying sequences. Default: "Actor".
- time_col
Character. Name of the column identifying time points. Default: "Time".
- action_col
Character. Name of the column containing actions/states. Default: "Action".
- time_prefix
Character. Prefix for time point columns in output. Default: "V".
- fill_na
Logical. Whether to fill missing time points with NA. Default: TRUE.
Value
A data frame in wide format, one row per sequence: the
id_col column followed by the time point columns
V1, V2, ... (named with time_prefix) holding the
action at each time point. With fill_na = TRUE short sequences
are padded with NA so every row shares the same columns; with
fill_na = FALSE only the time points present in every sequence
are kept.
Details
Converts long format data (one row per action) to the wide format expected
by build_network, tna::tna() and related functions.
If time_col contains non-integer values (e.g., timestamps), the function
will use the ordering within each sequence to create time indices.
See also
wide_to_long for the reverse conversion,
prepare_for_tna for preparing data for TNA analysis.