Learn R Programming

HARplus (version 1.0.1)

pivot_data: Pivot Data from SL4 or HAR Objects

Description

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")

Value

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

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".

Author

Pattawee Puangchit

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.

See Also

get_data_by_var, get_data_by_dims

Examples

Run this code
# 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"))

Run the code above in your browser using DataLab