Skip to contents

The S_units vector is a unit summation vector with products (energy carriers) in rows and units in columns. The row names for each vector are the various products in that row of .df. The column names for each vector are taken from the units column of .df.

Usage

calc_S_units(
  .df = NULL,
  matrix_class = c("matrix", "Matrix"),
  unit = MWTools::mw_cols$unit,
  R = MWTools::psut_cols$R,
  U = MWTools::psut_cols$U,
  V = MWTools::psut_cols$V,
  Y = MWTools::psut_cols$Y,
  s_units = MWTools::psut_cols$s_units,
  product_notation = RCLabels::from_notation,
  product_type = MWTools::row_col_types$product,
  unit_type = MWTools::row_col_types$unit
)

Arguments

.df

A data frame. Default is NULL.

matrix_class

The type of matrix to be created, one of "matrix" or "Matrix". Default is "matrix".

unit

A string unit for each row or the name of the unit column in .df. See MWTools::mw_cols.

R, U, V, Y

PSUT matrices or the names of matrix columns in .df. See MWTools::psut_cols.

s_units

The name of the output matrix or the output column. See MWTools::psut_cols.

product_notation

Notation for products. Default is RCLabels::from_notation.

product_type, unit_type

The types for products and units columns. See MWTools::row_col_types$unit.

Value

.df with an s_units column added.

Details

This function employs matsindf::matsindf_apply() internally, so unit can be a single string or the name of a column in .df. Similarly, R, U, V, and Y can be either matrices or the names of columns in .df.

Product names are taken from the prefixes of row or columns names of the R, U, V, and Y matrices.

The unit column will remain in .df on output and will need to be deleted afterward.

Examples

ilo_working_hours_data <- read.csv(file = MWTools::ilo_working_hours_test_data_path())
ilo_employment_data <- read.csv(file = MWTools::ilo_employment_test_data_path())
hmw_data <- prepareRawILOData(ilo_working_hours_data = ilo_working_hours_data,
                              ilo_employment_data = ilo_employment_data)
hmw_df <- hmw_data %>%
  calc_hmw_pfu() %>%
  # Keep only a few years for speed.
  dplyr::filter(Year %in% 2000:2002)
amw_df <- amw_test_data_path() %>%
  read.csv() %>%
  calc_amw_pfu() %>%
  # Keep only a few years for speed.
  dplyr::filter(Year %in% 2000:2002)
specify_energy_type_method(hmw_df, amw_df) %>%
  specify_product() %>%
  specify_TJ() %>%
  MWTools::specify_primary_production() %>%
  specify_useful_products() %>%
  specify_fu_machines() %>%
  specify_last_stages() %>%
  MWTools::add_row_col_meta() %>%
  MWTools::collapse_to_psut() %>%
  calc_S_units()
#> # A tibble: 12 × 11
#>    Country  Year Method Energy.type Last.stage Unit  R        U        V       
#>    <chr>   <dbl> <chr>  <chr>       <chr>      <chr> <list>   <list>   <list>  
#>  1 CHNM     2000 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  2 CHNM     2000 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  3 CHNM     2001 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  4 CHNM     2001 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  5 CHNM     2002 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  6 CHNM     2002 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  7 GBR      2000 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  8 GBR      2000 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#>  9 GBR      2001 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#> 10 GBR      2001 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#> 11 GBR      2002 PCM    E           Final      TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#> 12 GBR      2002 PCM    E           Useful     TJ    <dbl[…]> <dbl[…]> <dbl[…]>
#> # ℹ 2 more variables: Y <list>, S_units <list>