prep_psut | R Documentation |
Converts a tidy IEA data frame into a PSUT data frame
by collapsing the IEA data into PSUT matrices (R
, U
, V
, Y
, and S_units
).
prep_psut(
.tidy_iea_df,
matrix_class = c("matrix", "Matrix"),
year = IEATools::iea_cols$year,
ledger_side = IEATools::iea_cols$ledger_side,
flow_aggregation_point = IEATools::iea_cols$flow_aggregation_point,
flow = IEATools::iea_cols$flow,
product = IEATools::iea_cols$product,
e_dot = IEATools::iea_cols$e_dot,
unit = IEATools::iea_cols$unit,
supply = IEATools::ledger_sides$supply,
consumption = IEATools::ledger_sides$consumption,
matnames = IEATools::mat_meta_cols$matnames,
rownames = IEATools::mat_meta_cols$rownames,
colnames = IEATools::mat_meta_cols$colnames,
rowtypes = IEATools::mat_meta_cols$rowtypes,
coltypes = IEATools::mat_meta_cols$coltypes,
matvals = IEATools::psut_cols$matvals,
R = IEATools::psut_cols$R,
U_eiou = IEATools::psut_cols$U_eiou,
U_feed = IEATools::psut_cols$U_feed,
r_eiou = IEATools::psut_cols$r_eiou,
U = IEATools::psut_cols$U,
V = IEATools::psut_cols$V,
Y = IEATools::psut_cols$Y,
B = IEATools::psut_cols$B,
s_units = IEATools::psut_cols$s_units
)
.tidy_iea_df |
a tidy data frame that has been specified with |
matrix_class |
The type of matrix to be created, one of "matrix" or "Matrix". Default is "matrix". |
year , ledger_side , flow_aggregation_point , flow , product , e_dot , unit |
See |
supply , consumption |
See |
matnames , rownames , colnames , rowtypes , coltypes |
See |
matvals , R , U_eiou , U_feed , U , r_eiou , V , Y , s_units , B |
See |
This function bundles several others:
add_psut_matnames()
add_row_col_meta()
collapse_to_tidy_psut()
replace_null_RUV()
Furthermore, it extracts S_units
matrices using extract_S_units_from_tidy()
and adds those matrices to the data frame.
If .tidy_iea_df
is a zero-row data frame,
the return value is a zero-row data frame with expected columns.
A wide-by-matrix data frame with metadata columns and columns named for each type of matrix.
library(dplyr)
library(tidyr)
Simple <- load_tidy_iea_df() %>%
specify_all() %>%
prep_psut() %>%
pivot_longer(cols = c(R, U_EIOU, U_feed, V, Y, S_units),
names_to = "matnames",
values_to = "matval_simple")
S_units <- load_tidy_iea_df() %>%
specify_all() %>%
extract_S_units_from_tidy()
Complicated <- load_tidy_iea_df() %>%
specify_all() %>%
add_psut_matnames() %>%
add_row_col_meta() %>%
collapse_to_tidy_psut() %>%
spread(key = matnames, value = matvals) %>%
replace_null_RUV() %>%
full_join(S_units, by = c("Method", "EnergyType", "LastStage",
"Country", "Year")) %>%
gather(key = matnames, value = matvals, R, U_EIOU, U_feed,
V, Y, S_units) %>%
rename(matval_complicated = matvals)
# Simple and Complicated are same.
full_join(Simple, Complicated, by = c("Method", "EnergyType",
"LastStage", "Country",
"Year", "matnames")) %>%
dplyr::mutate(
same = matsbyname::equal_byname(matval_simple, matval_complicated)
) %>%
magrittr::extract2("same") %>%
as.logical() %>%
all()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.