View source: R/gridArithmetics.R
gridArithmetics | R Documentation |
Perform basic arithmetic operations between two or more grids (or factors).
gridArithmetics(..., operator = "*", template = NULL)
... |
Input grids or factors (numbers). The first element must be a grid, the rest could be either grids or numbers. |
operator |
Character string of arithmetic simbols ("+", "-", "/", "*"). The length must
be 1 (the same operator is used for all elements in |
template |
grid from which the structure (dates, variable name, etc..) is kept for
the output data (Default is the first grid in |
Lets imagine that elements in ...
are A, B and C, where A is a grid and
B and C are either grids or numbers. If operator is, for example, "+" (or c("+", "+")),
then the mathematical expression evaluated by gridArithmetics
is: A + B + C.
If operator is, for example, c("+", "/")
, then the expression is (A + B)/C.
If we would like to evaluate an expression such as A/(B + C), gridArithmetics
must be applied two times (see examples).
A grid
M. Iturbide
require(climate4R.datasets)
data("CMIP5_Iberia_pr")
data("EOBS_Iberia_pr")
cmip5 <- interpGrid(CMIP5_Iberia_pr, getGrid(EOBS_Iberia_pr))
A <- cmip5 ; B <- EOBS_Iberia_pr; C <- 100
# To evaluate (A - B) / B * C:
relative.delta <- gridArithmetics(A, B, B, C,
operator = c("-", "/", "*"),
template = NULL)
# More than one step needed to evaluate an expression of the type B/(A - B):
grid1 <- gridArithmetics(A, B, operator = "-")
newgrid <- gridArithmetics(B, grid1, operator = "/")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.