sort_iea_df | R Documentation |
The IEA data frame to be sorted can be either
(a) tidy (long) where each observation is on its own row and
there is a year
column present or
(b) wide where year columns are spread to the right.
sort_iea_df(
.iea_df,
col_names = IEATools::iea_cols,
country = col_names$country,
method = col_names$method,
energy_type = col_names$energy_type,
last_stage = col_names$last_stage,
year = col_names$year,
ledger_side = col_names$ledger_side,
flow_aggregation_point = col_names$flow_aggregation_point,
flow = col_names$flow,
sep = "_",
fap_flow = paste0(flow_aggregation_point, sep, flow),
product = col_names$product,
country_order = IEATools::countries,
method_order = IEATools::methods,
energy_type_order = IEATools::energy_types,
last_stage_order = IEATools::last_stages,
ledger_side_iea_order = IEATools::ledger_sides,
fap_flow_iea_order = IEATools::fap_flows,
product_iea_order = IEATools::products,
.clean_flow = ".clean_flow",
.clean_product = ".clean_product"
)
.iea_df |
the IEA data frame to be sorted |
col_names |
a list of column names in IEA data frames. Default is |
country |
the name of the country column in |
method |
the name of the method column in |
energy_type |
the name of the energy type column in |
last_stage |
the name of the last stage column in |
year |
the name of the year column in |
ledger_side |
the name of the ledger side column in |
flow_aggregation_point |
the name of the flow aggregation point column in |
flow |
the name of the flow column in |
sep |
a separator between the flow aggregation point column and the flow column. Used when uniting those two columns internally. Default is "_". |
fap_flow |
the name of the united flow aggregation point and flow column to be created internally in |
product |
the name of the product column in |
country_order |
the order in which to sort the |
method_order |
the order in which to sort the |
energy_type_order |
the order in which to sort the |
last_stage_order |
the order in which to sort the |
ledger_side_iea_order |
the order in which to sort the |
fap_flow_iea_order |
the order in which to sort the united |
product_iea_order |
the order in which to sort the |
.clean_flow |
the name of an internally-generated column in |
.clean_product |
the name of an internally-generated column in |
Sorting is accomplished (by default) using
the values of the arguments countries
, methods
,
energy_type
, last_stage
, year
(if present),
ledger_side
, fap_flows
, and
product
(in that order of precedence).
Years are sorted if the year
column is present (a tidy data frame).
If years are not present, they are assumed to be spread to the right
to create a wide data frame.
Wide data frames are sorted in the same order.
a version of .tidy_iea_df
sorted in IEA order
library(dplyr)
tidy <- load_tidy_iea_df()
# See first and last rows
head(tidy)
tail(tidy)
# Move the first row to the bottom to put everything out of order
unsorted <- tidy[-1, ] %>%
bind_rows(tidy[1, ])
head(unsorted)
tail(unsorted)
# Now sort it
sorted <- sort_iea_df(unsorted)
head(sorted)
tail(sorted)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.