This function adds a column of matrix names to a tidy data frame wherein each row of .DF is a single value in an energy conversion chain. The default argument values assume that .DF uses IEA-style nomenclature and terminology, although .DF does not necessarily need to contain IEA data.

add_matnames_iea(
  .DF,
  ledger_side = "Ledger.side",
  energy = "E.dot",
  flow_aggregation_point = "Flow.aggregation.point",
  flow = "Flow",
  supply_side = "Supply",
  consumption_side = "Consumption",
  eiou = "Energy industry own use",
  neg_supply_in_fd = c("Exports", "International aviation bunkers",
    "International marine bunkers", "Losses", "Statistical differences", "Stock changes"),
  use_R = FALSE,
  matname = "matname",
  U_excl_EIOU = "U_excl_EIOU",
  U_EIOU = "U_EIOU",
  R = "R",
  V = "V",
  Y = "Y"
)

Arguments

.DF

a data frame with ledger_side, energy, flow_aggregation_point, and flow columns.

ledger_side

the name of the column in .DF that contains ledger side (a string). Default is "Ledger.side".

energy

the name of the column in .DF that contains energy and exergy values (a string). Default is "E.dot".

flow_aggregation_point

the name of the column in .DF that contains flow aggregation point information. Default is "Flow.aggregation.point".

flow

the name of the column in .DF that contains flow information. Default is "Flow".

supply_side

the identifier for items on the supply side of the ledger (a string). Default is "Supply".

consumption_side

the identifier for items on the consumption side of the ledger (a string). Default is "Consumption".

eiou

the identifier for items that are energy industry own use. Default is ""Energy industry own use".

neg_supply_in_fd

identifiers for flow items that, when negative, are entries in the final demand (Y) matrix.

use_R

tells whether to use a separate resources matrix (R). Default is "FALSE", for now.

matname

the name of the output column containing the name of the matrix to which a row's value belongs (a string). Default is "matname".

U_excl_EIOU

the name for the use matrix that excludes energy industry own use (a string). Default is "U_excl_EIOU".

U_EIOU

the name for the energy industry own use matrix. Default is "U_EIOU".

R

the name for the resource matrix (a string). Default is "R".

V

the name for the make matrix (a string). Default is "V".

Y

the name for the final demand matrix (a string). Default is "Y".

Value

.DF with an added column, matname.

Details

In a reasonable workflow, this function would be followed by a call to add_row_col_meta and collapse_to_matrices.

This function respects groups when identifying entries in the resource matrix (R). So be sure to group .DF before calling this function, if that is warranted.

Internally, this function adds a temporary column to .DF called ".R". An error will occur if .DF already has a column named ".R".

Examples

library(dplyr) UKEnergy2000tidy %>% group_by(Country, Year, Energy.type, Last.stage) %>% add_matnames_iea() %>% glimpse()
#> Observations: 193 #> Variables: 11 #> Groups: Country, Year, Energy.type, Last.stage [4] #> $ Country <chr> "GBR", "GBR", "GBR", "GBR", "GBR", "GBR", "GBR… #> $ Year <dbl> 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000… #> $ Ledger.side <chr> "Supply", "Supply", "Supply", "Supply", "Suppl… #> $ Flow.aggregation.point <chr> "Total primary energy supply", "Total primary … #> $ Energy.type <chr> "E", "E", "E", "E", "E", "E", "E", "E", "E", "… #> $ Last.stage <chr> "Final", "Final", "Final", "Final", "Final", "… #> $ Flow <chr> "Resources - Crude", "Resources - NG", "Gas we… #> $ Product <chr> "Crude", "NG", "NG - Wells", "Crude - Fields",… #> $ E.dot <dbl> 50000, 43000, 43000, 50000, 47500, 41000, 2050… #> $ Unit <chr> "ktoe", "ktoe", "ktoe", "ktoe", "ktoe", "ktoe"… #> $ matname <chr> "V", "V", "V", "V", "V", "V", "V", "V", "V", "…