Skip to contents

Replaces specific values in a column based on a provided mapping file. Supports renaming across nested data structures and preserves factor levels.

Usage

rename_value(data, column_name = NULL, mapping.file)

Arguments

data

Data structure (data frame, list, or nested combination).

column_name

Character. Column to modify. If `NULL`, the function extracts it from `mapping.file`.

mapping.file

Data frame with `"OldName"` and `"NewName"` columns for renaming.

Value

The same data structure with specified values replaced.

Author

Pattawee Puangchit

Examples

# Load Sample Data:
sl4_data1 <- HARplus::load_sl4x(system.file("extdata/in", "EXP1.sl4", 
                                package = "GTAPViz"))
# Get Data by Variable Name
sl4_data1 <- HARplus::get_data_by_var(c("qgdp", "EV"),sl4_data1)

# Rename variables in a dataset
rename_map <- data.frame(OldName = c("qgdp", "EV"), 
                        NewName = c("Real GDP", "Welfare"))
gtap_data <- rename_value(sl4_data1, column_name = "Variable", 
                          mapping.file = rename_map)