Learn R Programming

HARplus (version 1.0.1)

rename_dims: Rename Dimensions in SL4 or HAR Objects

Description

Renames dimension and list names in structured SL4 or HAR objects.

Usage

rename_dims(data_obj, mapping_df, rename_list_names = FALSE)

Value

The modified SL4 or HAR object with updated dimension names and, optionally, updated list names.

Arguments

data_obj

A structured SL4 or HAR object.

mapping_df

A two-column data frame where the first column (old) contains the current names, and the second column (new) contains the new names.

rename_list_names

Logical. If TRUE, renames list element names. Default is FALSE.

Author

Pattawee Puangchit

Details

  • Replaces old dimension names with new ones as specified in mapping_df.

  • If rename_list_names = TRUE, renames list element names as well.

  • Ensures consistency across SL4 and HAR datasets.

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

# Define a renaming map
mapping_df <- data.frame(
  old = c("REG", "COMM"),
  new = c("Region", "Commodity")
)

# Rename columns in the dataset
rename_dims(sl4_data, mapping_df)

# Rename both columns and list names
rename_dims(sl4_data, mapping_df, rename_list_names = TRUE)

Run the code above in your browser using DataLab