layerOp: Layer Operation

View source: R/layerOp.R

layerOpR Documentation

Layer Operation

Description

Perform an operation on some layers with a Field to make a new layer within the Field (or change their values, or remove them). For example, adding some layers, dividing one layer by another or setting some layers to a constant value. NOTE: this function performs 'in-place' operations which, unlike normal R functions, will actually change the objects passed in as the arguments, not just return a value! Read what this means below.

Usage

layerOp(x, operator, layers, new.layer, constant = 1)

Arguments

x

The x object on which we are operating.

operator

The operator we are applying, can be:

  • "+" (or "sum" or "add") Add the layers, can apply to any number of layers

  • "mean" (or "average") Average the layers, can apply to any number of layers

  • "*" (or "multiply" or "product") Multiply the layers, can apply to any number of layers

  • "-" (or "subtract" or "minus") Subtract one layer from another. Requires exactly two layers to be specified, subtracts the second from the first, ie. layer1 - layer 2.

  • "/" (or "divide" or "through") Divide one layer by another. Nore this does 'safe division' which returns zero if the denomination is zero. Requires exactly two layers to be specified, divides the first by the second, ie. layer1 / layer 2.

  • "max.layer" Gets the layer with the maximum value from the input layers (is a layer of factors). If they are all zero at a point then "None" is assigned. In the case of ties, the first layer in the layers arguement will be returned as the max.

  • "min.layer" Gets the layer with the minimum value from the input layers (is a layer of factors). If they are all zero at a point then "None" is assigned. In the case of ties, the first layer in the layers arguement will be returned as the min.

  • "mulc"/"divc"/"addc"/"subc" Multiplies, divides, adds or subtracts the layer with a numeric value in the "constant" argument

  • any numeric value Sets each of the layers specified uniformly to the numeric value specified, most usefuly for 0. Previously not existing layers in the layers and new.layer argument will be created.

  • NULL A special case of the above which removes the layers from the Field

  • Whatever function Now we are into crazy territory! You can provide any function (the actual function, not a string ) that operates on a vector of numerics and it might just work! Works for sd, var, min and max, but your mileage may vary.

  • Something else?Contact the author!

layers

The names of the layers upon which to operate (as a vector of characters). Furthermore, one can utilise a handy trick whereby any layer specified,

new.layer

A single character specifying the name of the new layer, will over-write an existing layer if already present. Will be built automatically if not specified.

constant

A numeric used for the "mulc"/"divc"/"addc"/"subc" modes

Value

A Field (but not this is not strictly necessary since the objects are changed in place)

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de


MagicForrest/DGVMTools documentation built on Aug. 23, 2024, 8:05 a.m.