View source: R/superAggregate.R
superAggregate | R Documentation |
Function which applies aggregation functions over a subset of an magpie or lpj object.
superAggregate(data, aggr_type, level="reg", weight=NULL, na.rm=TRUE,
crop_aggr=FALSE, ...)
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
|
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) |
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.
Benjamin Bodirsky, Jan Philipp Dietrich, Florian Humpenoeder
colSums
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.