convert_to_net_trade | R Documentation |
This function enables to convert a .tidy_iea_df
to
a new .tidy_iea_df
in which trade flows are reported as net flows.
So, if a given region or country both imports and exports a given product,
the function will report only the difference between imports and exports,
depending on which flow is dominant. See Details for uses.
convert_to_net_trade(
.tidy_iea_df,
imports = IEATools::interface_industries$imports,
exports = IEATools::interface_industries$exports,
country = IEATools::iea_cols$country,
e_dot = IEATools::iea_cols$e_dot,
flow = IEATools::iea_cols$flow,
year = IEATools::iea_cols$year,
ledger_side = IEATools::iea_cols$ledger_side,
flow_aggregation_point = IEATools::iea_cols$flow_aggregation_point,
product = IEATools::iea_cols$product,
.net_imports = "Net_Imports"
)
.tidy_iea_df |
The |
imports |
The name of the Imports flows in the |
exports |
The name of the Exports flows in the |
country, e_dot, flow, year, ledger_side, flow_aggregation_point, product |
See |
.net_imports |
A temporary column that calculates net imports as the difference between imports and exports. Default is "Net_Imports". |
The function may be use after aggregating regions with the
IEATools::aggregate_regions()
function, or may be applied to IEA data for
aggregated regions (such as World) for which both imports and exports are reported
for a given product.
A .tidy_iea_df
for which trade flows are converted to net trade.
# In this example, we gather all flows for countries A and B
# in a new "AB" region, for which both imports and exports are reported for some products.
tidy_AB_data %>%
dplyr::mutate(Country = "AB") %>%
dplyr::filter(stringr::str_detect(Flow, "Imports") | stringr::str_detect(Flow, "Exports")) %>%
print()
# After running the function, only either imports or exports are reported for each product.
tidy_AB_data %>%
dplyr::mutate(Country = "AB") %>%
convert_to_net_trade() %>%
dplyr::filter(stringr::str_detect(Flow, "Imports") | stringr::str_detect(Flow, "Exports")) %>%
print()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.