Skip to contents

A tidy data frame of muscle work information can be converted to a matsindf data frame via this function.

Usage

collapse_to_psut(
  .df,
  matrix_class = c("matrix", "Matrix"),
  country = MWTools::mw_cols$country,
  year = MWTools::mw_cols$year,
  method = MWTools::mw_cols$method,
  energy_type = MWTools::mw_cols$energy_type,
  last_stage = MWTools::mw_cols$last_stage,
  unit = MWTools::mw_cols$unit,
  e_dot = MWTools::mw_cols$e_dot,
  matnames = MWTools::mat_meta_cols$matnames,
  matvals = MWTools::mat_meta_cols$matvals,
  rownames = MWTools::mat_meta_cols$rownames,
  colnames = MWTools::mat_meta_cols$colnames,
  rowtypes = MWTools::mat_meta_cols$rowtypes,
  coltypes = MWTools::mat_meta_cols$coltypes
)

Arguments

.df

A data frame created by add_row_col_meta() so that it contains metadata columns for creating PSUT matrices.

matrix_class

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

country, year, method, energy_type, last_stage, unit, e_dot

See MWTools::mw_cols.

matnames, matvals, rownames, colnames, rowtypes, coltypes

See MWTools::mat_meta_cols.

Value

A matsindf-style, wide-by-matrices data frame of muscle work matrices.

Details

Prior to forming matrices, this function deletes unneeded columns (columns that are neither metadata nor energy values). It also aggregates data frame rows that will end up at the same row, column location in the matrices.

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()
#> # A tibble: 12 × 10
#>    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[…]>
#> # ℹ 1 more variable: Y <list>