pivot_data_hierarchy {HARplus}R Documentation

Create Hierarchical Pivot Table from SL4 or HAR Objects

Description

Creates hierarchical pivot tables from structured SL4 or HAR data, with optional Excel export. Supports both single data frames and nested lists, preserving dimension hierarchies.

Usage

pivot_data_hierarchy(
  data_obj,
  pivot_cols,
  name_repair = "unique",
  export = FALSE,
  file_path = NULL,
  xlsx_filename = NULL
)

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 in order of hierarchy.

name_repair

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

export

Logical. If TRUE, exports result to Excel. Default is FALSE.

file_path

Character. Required if export = TRUE. The path for Excel export.

xlsx_filename

Character. The name for the Excel file when using multi_sheet_xlsx. If NULL, uses the name of the dataset. Default is NULL.

Details

Value

A pivoted data object with hierarchical structure:

Author(s)

Pattawee Puangchit

See Also

pivot_data

Examples


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

# Extract data
data_multiple <- get_data_by_var(c("qo", "pca"), sl4_data)

# Create hierarchical pivot without export
pivot_hier <- pivot_data_hierarchy(data_multiple, 
                                   pivot_cols = c("REG", "COMM"))

# Create and export to Excel in one step
pivot_export <- pivot_data_hierarchy(data_multiple, 
                                     pivot_cols = c("REG", "COMM"),
                                     export = TRUE,
                                     file_path = file.path(tempdir(), "pivot_output.xlsx"))



[Package HARplus version 1.0.1 Index]