Learn R Programming

magclass (version 6.13.2)

magpply: magpply

Description

apply command for magpieobjects. Very efficient for replacing loops.

Usage

magpply(X, FUN, MARGIN = NULL, DIM = NULL, ..., INTEGRATE = FALSE)

Value

magpie object

Arguments

X

magpie object

FUN

function that shall be applied X

MARGIN

dimension over which FUN shall be applied (like a loop over that dimension). This dimension will be preserved in the output object (see also DIM).

DIM

dimension in which FUN shall be applied. This dimension will be missing in the output. DIM and MARGIN are opposite ways of expressing the dimensions to be addressed and you must only use one of them with MARGIN excluding dimensions from the calculation and DIM including them.

...

further parameters passed on to FUN

INTEGRATE

if TRUE, the output will be filled into an magpie object of the same dimensionality as X

Author

Jan Philipp Dietrich, Benjamin Leon Bodirsky

Examples

Run this code

pop <- maxample("pop")
magpply(pop, FUN = sum, MARGIN = 2)
fourdim <- pop * setNames(pop, c("jkk", "lk"))
magpply(fourdim, FUN = sum, MARGIN = c(1, 3.1))

Run the code above in your browser using DataLab