extract_S_units_from_tidy: Extract a unit summation matrix from a tidy data frame

View source: R/psut.R

extract_S_units_from_tidyR Documentation

Extract a unit summation matrix from a tidy data frame

Description

Unit 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_units matrix 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

See IEATools::row_col_types.

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".

Details

.tidy_iea_df should be grouped as needed, typically on Country, Year, Energy.type, Last.stage, etc., but not on Unit, Flow or Product. .tidy_iea_df is typically obtained from tidy_iea_df().

Value

a data frame containing grouping variables and a new column of unit summation matrices called s_unit.

Examples

library(dplyr)
load_tidy_iea_df() %>% 
  extract_S_units_from_tidy()

MatthewHeun/IEATools documentation built on Feb. 6, 2024, 3:29 p.m.