aggregate_dt: Aggregate values in a data.table object using a mapping. If...

View source: R/aggregate.R

aggregate_dtR Documentation

Aggregate values in a data.table object using a mapping. If no weight is given, the value for the aggregated categories is the sum of the parts. Otherwise, the weight is used to calculate a weighted average accross the parts.

Description

Aggregate values in a data.table object using a mapping. If no weight is given, the value for the aggregated categories is the sum of the parts. Otherwise, the weight is used to calculate a weighted average accross the parts.

Usage

aggregate_dt(
  data,
  mapping,
  fewcol = "region",
  yearcol = "year",
  manycol = "iso",
  datacols = "data",
  valuecol = "value",
  weights = NULL,
  weightcol = "weight"
)

Arguments

data

a magpie object.

mapping

a mapping between the aggregated categories in the data and ISO3 countrycodes. *All* regions in 'data' have to be part of the mapping.

fewcol

name of the column containing aggregated categories. Default is "region".

yearcol

name of the column containing time step info. Default is "year".

manycol

name of the column containing dis-aggregated categories. Default is "iso".

datacols

index columns that label categories which have to be treated seperately when aggregating with a weight.

valuecol

name of the column with the value to aggregate, default is 'value'.

weights

table with weights for a (weighted average) aggregation, the name of the column with the aggregated categories has to be 'manycol'. If columns (other than the column with the aggregated category) of the 'weights' coincide with columns of the data, the respective columns are considered when joining.

weightcol

column with the weights for aggregation, default is 'weight'.


pik-piam/rmndt documentation built on April 21, 2024, 4:31 a.m.