wide_to_long: Convert Wide Sequences to Long Format

View source: R/data_conversion.R

wide_to_longR Documentation

Convert Wide Sequences to Long Format

Description

Convert sequence data from wide format (one row per sequence, columns as time points) to long format (one row per action).

Usage

wide_to_long(
  data,
  id_col = NULL,
  time_prefix = "V",
  action_col = "Action",
  time_col = "Time",
  drop_na = TRUE
)

Arguments

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.

Details

This function converts data from the format produced by simulate_sequences() to the long format used by many TNA functions and analyses.

Value

A data frame in long format with columns:

id

Sequence identifier (integer).

Time

Time point within the sequence (integer).

Action

The action/state at that time point (character).

Any additional columns from the original data are preserved.

See Also

long_to_wide for the reverse conversion, prepare_for_tna for preparing data for TNA analysis.

Examples

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)


Nestimate documentation built on April 20, 2026, 5:06 p.m.