convert_units {GTAPViz} | R Documentation |
Convert Units in GTAP Data
Description
Converts values in a dataset to different units based on predefined transformations or custom scaling. Supports manual and automatic conversions for economic and trade-related metrics.
Usage
convert_units(
data,
change_unit_from = NULL,
change_unit_to = NULL,
adjustment = NULL,
value_col = "Value",
unit_col = "Unit",
variable_select = NULL,
variable_col = "Variable",
scale_auto = NULL
)
Arguments
data |
A data structure (list, data frame, or nested combination). |
change_unit_from |
Character vector. Units to be converted (case-insensitive). |
change_unit_to |
Character vector. Target units corresponding to |
adjustment |
Character or numeric vector. Specifies conversion operations (e.g., |
value_col |
Character. Column name containing values to adjust (default: |
unit_col |
Character. Column name containing unit information (default: |
variable_select |
Optional character vector. If provided, only these variables are converted. |
variable_col |
Character. Column name containing variable identifiers (default: |
scale_auto |
Optional character vector of predefined conversion rules:
|
Details
If both change_unit_from
and scale_auto
are provided, the function prompts the user
to choose between manual and automatic conversion.
Value
A data structure with values converted to the specified units.
Author(s)
Pattawee Puangchit
See Also
add_mapping_info
, rename_value
, sort_plot_data
Examples
# Load Data:
input_path <- system.file("extdata/in", package = "GTAPViz")
sl4.plot.data <- readRDS(file.path(input_path, "sl4.plot.data.rds"))
# Convert million USD to billion USD
gtap_data <- convert_units(sl4.plot.data,
change_unit_from = "million USD",
change_unit_to = "billion USD",
adjustment = "/1000"
)
# Automatic conversion from percent to fraction
gtap_data <- convert_units(sl4.plot.data, scale_auto = "pct2frac")