gridArithmetics: Basic arithmetic operations between grids and numbers

View source: R/gridArithmetics.R

gridArithmeticsR Documentation

Basic arithmetic operations between grids and numbers

Description

Perform basic arithmetic operations between two or more grids (or factors).

Usage

gridArithmetics(..., operator = "*", template = NULL)

Arguments

...

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 ...) or length(...) - 1 (See Details).

template

grid from which the structure (dates, variable name, etc..) is kept for the output data (Default is the first grid in ...).

Details

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).

Value

A grid

Author(s)

M. Iturbide

Examples

 
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 = "/")


SantanderMetGroup/transformeR documentation built on Nov. 25, 2024, 1:25 p.m.