Extract a unit summation matrix from a tidy data frame
extract_S_units_from_tidy.RdUnit summation matrices have products in rows and units in columns, with
1s where a product is expressed in the unit and 0s otherwise.
Usage
extract_S_units_from_tidy(
.tidy_iea_df,
matrix_class = c("matrix", "Matrix"),
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,
matnames = IEATools::mat_meta_cols$matnames,
product_type = IEATools::row_col_types$product,
unit_type = IEATools::row_col_types$unit,
s_units = IEATools::psut_cols$s_units,
.val = ".val",
.rowtype = ".rowtype",
.coltype = ".coltype"
)Arguments
- .tidy_iea_df
the tidy data frame from which a unit summation
S_unitsmatrix is to be formed.- matrix_class
The type of matrix to be created, one of "matrix" or "Matrix". Default is "matrix".
- ledger_side, flow_aggregation_point, flow, product, e_dot, unit, matnames
See
IEATools::iea_cols.- product_type, unit_type
- s_units
See
IEATools::psut_cols.- .val
the name of a temporary value column to be created in
.tidy_iea_df. Default is ".val".- .rowtype
the name of a temporary rowtype column created in
.tidy_iea_df. Default is ".rowtype".- .coltype
the name of a temporary coltype column created in
.tidy_iea_df. Default is ".coltype".
Value
a data frame containing grouping variables and a new column of unit summation matrices called s_unit.
Details
.tidy_iea_df should be grouped as needed, typically on
Country, Year, EnergyType, Last.stage, etc., but
not on Unit, Flow or Product.
.tidy_iea_df is typically obtained from tidy_iea_df().
Examples
library(dplyr)
load_tidy_iea_df() %>%
extract_S_units_from_tidy()
#> Country Method EnergyType LastStage Year
#> 1 GHA PCM E Final 1971
#> 2 GHA PCM E Final 2000
#> 3 ZAF PCM E Final 1971
#> 4 ZAF PCM E Final 2000
#> S_units
#> 1 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#> 2 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#> 3 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
#> 4 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1