prepare_sequence_panel: Prepare longitudinal or panel sequence data

View source: R/sequence-panel.R

prepare_sequence_panelR Documentation

Prepare longitudinal or panel sequence data

Description

Validates a collection of sequences observed repeatedly for the same panel units and creates an auditable panel index. Each sequence must map to exactly one panel unit and one occasion.

Usage

prepare_sequence_panel(
  data,
  panel_id_col,
  occasion_col,
  sequence_id_col = "sequence_id",
  order_col = "sequence_order",
  state_col = "state",
  metadata_cols = NULL,
  require_unique_occasions = TRUE
)

Arguments

data

Long-format sequence data or a prepared gp3sequences result.

panel_id_col

Column identifying the repeatedly observed unit.

occasion_col

Column identifying the wave, visit, or occasion.

sequence_id_col, order_col, state_col

Core sequence columns.

metadata_cols

Optional columns that must remain constant within each sequence.

require_unique_occasions

Require at most one sequence per panel unit and occasion.

Value

An object of class gp3_sequence_panel containing canonical data, a panel index, state levels, and mapping information.

Examples

panel <- data.frame(
  participant_id = rep(c("p1", "p2"), each = 8L),
  occasion = rep(rep(c(1, 2), each = 4L), times = 2L),
  sequence_id = rep(c("p1_w1", "p1_w2", "p2_w1", "p2_w2"), each = 4L),
  sequence_order = rep(1:4, times = 4L),
  state = c("A", "B", "C", "D", "A", "C", "C", "D",
            "D", "C", "B", "A", "D", "B", "B", "A")
)
prepare_sequence_panel(panel, "participant_id", "occasion")

gp3sequences documentation built on Aug. 23, 2026, 5:10 p.m.