superAggregate: superAggregate

View source: R/superAggregate.R

superAggregateR Documentation

superAggregate

Description

Function which applies aggregation functions over a subset of an magpie or lpj object.

Usage

superAggregate(data, aggr_type, level="reg", weight=NULL, na.rm=TRUE,
crop_aggr=FALSE, ...)

Arguments

data

An MAgPIE or LPJ object

aggr_type

Aggregation Type. Can be any function for one or two objects (data and weight) of the same size. Currently pre-supported functions: "sum","mean","weighted_mean".

level

Aggregation level: Either a level type (as a name) or a vector of 3-Character region names with the same length as the data has cells. Allowed level types are global "glo", regional "reg", per Country "country" and per REMIND regions "remind_reg". "country" and "remind_reg" are only supported for 0.5 grid datacells with 59199 cells and are always returned as arrays. If you use a vector of regions the aggregation will take place according to your regions.

weight

Currently only used for weighted_mean (see weighted.mean, yet also applicable for individualized functions. Has to be of the same size as data.

na.rm

If TRUE, NAs are ignored both in data and weight.

crop_aggr

determines whether output should be crop-specific (FALSE) or aggregated over all crops (TRUE). The method used for aggregation is set by aggr_type (Currently works only for levels "reg" and "glo")

...

additional arguments for the aggregation method for the standard functions (not for self-created ones)

Value

In the case of level="glo" or "reg", the function returns a MAgPIE object. In the case of level="country" an array is returned. In the case of an LPJ object being aggregated, a list of MAgPIE objects is returned, each entry being one of the 4th dimension slices.

Author(s)

Benjamin Bodirsky, Jan Philipp Dietrich, Florian Humpenoeder

See Also

colSums

Examples


data(population_magpie)
superAggregate(population_magpie,"sum",level="glo")
superAggregate(population_magpie,"mean",level="glo")
superAggregate(population_magpie,"weighted_mean",level="glo",weight=population_magpie)
aggregation_function<-function(func_data,func_weight) {
  colMeans(func_data)
}
superAggregate(population_magpie,aggregation_function,level="glo",weight=population_magpie)


pik-piam/luscale documentation built on April 27, 2024, 2:11 p.m.