magpie-class | R Documentation |
The MAgPIE class is a data format for cellular MAgPIE data with a close
relationship to the array data format. is.magpie
tests if x
is
an MAgPIE-object, as.magpie
transforms x
to an MAgPIE-object
(if possible).
x |
An object that should be either tested or transformed as/to an MAgPIE-object. |
... |
additional arguments supplied for the conversion to a MAgPIE
object. Allowed arguments for arrays and dataframes are |
Objects can be created by calls of the form
new("magpie", data, dim, dimnames, ...)
. MAgPIE objects have three
dimensions (cells,years,datatype) and the dimensionnames of the first
dimension have the structure "REGION.cellnumber". MAgPIE-objects behave the
same like array-objects with 2 exceptions:
1.Dimensions of the object
will not collapse (e.g. x[1,1,1]
will remain 3D instead of becoming
1D)
2.It is possible to extract full regions just by typing
x["REGIONNAME",,]
.
Please mind following standards:
Header must not contain any purely
numeric entries, but combinations of characters and numbers are allowed
(e.g. "bla","12" is forbidden, wheras "bla","b12" is allowed)
Years
always have the structure "y" + 4-digit number, e.g. "y1995"
Regions
always have the structure 3 capital letters, e.g. "AFR" or "GLO"
This
standards are necessary to allow the scripts to detect headers, years and
regions properly and to have a distinction to other data.
Jan Philipp Dietrich
read.magpie
, write.magpie
,
getRegions
, getYears
, getNames
,
getCPR
, ncells
, nyears
,
ndata
showClass("magpie")
pop <- maxample("pop")
# returning PAO and PAS for 2025
pop["PA", 2025, , pmatch = "left"]
# returning CPA for 2025
pop["PA", 2025, , pmatch = "right"]
# returning CPA PAO and PAS for 2025
pop["PA", 2025, , pmatch = TRUE]
# returning PAS and 2025
pop["PAS", 2025, ]
# return all entries for year 2025
pop[2025, dim = 2]
# returning everything but values for PAS or values for 2025
pop["PAS", 2025, , invert = TRUE]
# accessing subdimension via set name
a <- maxample("animal")
a[list(country = "NLD", y = "53p25"), , list(species = c("rabbit", "dog"))]
# please note that the list elements act as filter. For instance, the
# following example will not contain any dogs as the data set does
# not contain any dogs which are black.
a[list(country = "NLD", y = "53p25"), , list(species = c("rabbit", "dog"), color = "black")]
# it is also possible to extract given combinations of subdimensions
# via a data-frame
df <- data.frame(getItems(a, 3, split = TRUE, full = TRUE))[c(1, 3, 4), ][3:2]
getItems(a[df], 3)
# Unknown dimensions to be added in output!
df$blub <- paste0("bl", 1:dim(df)[1])
getItems(a[df], 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.