grouped_aggregates: Perform grouping aggregations on PSUT matrices

View source: R/aggregates.R

grouped_aggregatesR Documentation

Perform grouping aggregations on PSUT matrices

Description

It is often helpful to aggregate data into industry or product categories, such as "Anthracite" and "Brown coal" to "Coal and coal products" or "Domestic aviation" and "Domestic navigation" to "Transport". With the help of an aggregation_map, this function performs such aggregations for a set of PSUT matrices.

Usage

grouped_aggregates(
  .sut_data = NULL,
  aggregation_map,
  margin = c(1, 2),
  pattern_type = "exact",
  R = Recca::psut_cols$R,
  U = Recca::psut_cols$U,
  U_feed = Recca::psut_cols$U_feed,
  U_eiou = Recca::psut_cols$U_eiou,
  r_eiou = Recca::psut_cols$r_eiou,
  V = Recca::psut_cols$V,
  Y = Recca::psut_cols$Y,
  S_units = Recca::psut_cols$S_units,
  R_aggregated_colname = paste0(Recca::psut_cols$R, aggregated_suffix),
  U_aggregated_colname = paste0(Recca::psut_cols$U, aggregated_suffix),
  U_feed_aggregated_colname = paste0(Recca::psut_cols$U_feed, aggregated_suffix),
  U_eiou_aggregated_colname = paste0(Recca::psut_cols$U_eiou, aggregated_suffix),
  r_eiou_aggregated_colname = paste0(Recca::psut_cols$r_eiou, aggregated_suffix),
  V_aggregated_colname = paste0(Recca::psut_cols$V, aggregated_suffix),
  Y_aggregated_colname = paste0(Recca::psut_cols$Y, aggregated_suffix),
  S_units_aggregated_colname = paste0(Recca::psut_cols$S_units, aggregated_suffix),
  aggregated_suffix = Recca::aggregate_cols$aggregated_suffix
)

Arguments

.sut_data

A data frame of matrices to be despecified and aggregated.

aggregation_map

Aggregation details. See documentation for matsbyname::aggregate_byname() for further information.

margin

1, 2, or c(1, 2) for row aggregation, column aggregation, or both. Can be a row or column type. Default is c(1, 2).

pattern_type

See RCLabels::make_or_pattern(). Default is "exact".

R, U, U_feed, U_eiou, r_eiou, V, Y, S_units

Matrices or names of columns in .sut_data to be despecified and aggregated. See Recca::psut_cols.

R_aggregated_colname, U_aggregated_colname, U_feed_aggregated_colname, U_eiou_aggregated_colname, r_eiou_aggregated_colname, V_aggregated_colname, Y_aggregated_colname, S_units_aggregated_colname

Names of aggregated matrices or columns.

aggregated_suffix

A string suffix used to form the names for aggregated matrices. Default is "_aggregated".

Details

Internally, this function uses matsbyname::aggregate_byname(). See its documentation for details on the format for the aggregation_map.

Value

PSUT matrices aggregated according to aggregation_map.

Examples

UKEnergy2000mats %>%
  tidyr::pivot_wider(names_from = matrix.name, values_from = matrix) %>%
  grouped_aggregates(aggregation_map = list(`Oil and oil products` =
                                            c("Crude", "Diesel", "Petrol")),
                     pattern_type = "leading",
                     margin = "Product")

MatthewHeun/Recca documentation built on Feb. 9, 2024, 6:18 p.m.