Skip to contents

Transforms long-format SL4 or HAR data into wide format by pivoting selected columns. Supports both single data frames and nested lists.

Usage

pivot_data(data_obj, pivot_cols, name_repair = "unique")

Arguments

data_obj

A list or data frame. The SL4 or HAR data to pivot.

pivot_cols

Character vector. Column names to use as pivot keys.

name_repair

Character. Method for handling duplicate column names ("unique", "minimal", "universal"). Default is "unique".

Value

A transformed data object where the specified pivot_cols are pivoted into wide format.

Details

  • Uses tidyr::pivot_wider() internally to reshape data.

  • Allows multiple columns to be pivoted simultaneously.

  • Recursively processes nested lists, ensuring all data frames are transformed.

Author

Pattawee Puangchit

Examples

# Import sample data:
sl4_data <- load_sl4x(system.file("extdata", "TAR10.sl4", package = "HARplus"))

# Extract multiple variables
data_multiple <- get_data_by_var(c("qo", "qxs"), sl4_data)

# Pivot a single column
pivoted_data <- pivot_data(data_multiple, pivot_cols = "REG")

# Pivot multiple columns
pivoted_data_multi <- pivot_data(data_multiple, pivot_cols = c("REG", "COMM"))