copyLayers: Copy layers from one Field to another

View source: R/copyLayers.R

copyLayersR Documentation

Copy layers from one Field to another

Description

This function does not check the dimensions columns are identical. Any points in the 'from' object which are not in the 'to' object are ignored, and any points in the 'to' object which don't have corresponding points in the 'from' object are assigned NA, unless keep.all.to is set to FALSE .

Usage

copyLayers(
  from,
  to,
  layer.names,
  new.layer.names = NULL,
  keep.all.to = TRUE,
  keep.all.from = TRUE,
  tolerance = NULL,
  fill.dims = TRUE
)

Arguments

from

The Field/Comparison/data.table that the layers are to be copied from.

to

The Field/Comparison/data.table that the layers are to be copied to.

layer.names

The layers to be copied from the "from" argument

new.layer.names

The new names that the layers should have in the 'to' object. Use this to avoid naming conflict whereby, for example, if a layer "Total" is copied to an object which already has a "Total" layer then they layers will be names "Total.x" and "Total.y".

keep.all.to

Logical, if set to FALSE, all points in the 'to' object which don't have corresponding points in the 'from' object are removed.

keep.all.from

Logical, if set to FALSE, all points in the 'from' object which don't have corresponding points in the 'to' object are removed.

tolerance

Numeric, passed to copyLayers. Defines how close the longitudes and latitudes of the gridcells in from and to need to be to the coordinates in order to get a match. Can be a single numeric (for the same tolerance for both lon and lat) or a vector of two numerics (for lon and lat separately). Default is no rounding (value is NULL) and so is fine for most regular spaced grids. However, setting this can be useful to force matching of coordinates with many decimal places which may have lost a small amount of precision and so don't match exactly.

fill.dims

Logical, if TRUE (the default) and if the 'from' Field/data.table has less dimensions than the 'to' Field/data.table, then just fill in all the values of that dimension with the same data. Ie if if the 'from' table has no months but the to table does, just fill the same value into all months.

Details

This function allows layers (reminder, they are implemented as columns in a data.table) to be copied from one Field, Comaprison or data.table to another. This function is used extensively internally but can also be useful for user doing more advanced analysis and plotting. For example, is particularly useful for colouring or facetting a plot of one variable by another one. To give a more concrete example, one could use a biome classification to split (facet) a data-vs-model scatter plot.

Value

A Field, Comparison or data.table comprising the 'to' object with the new layers added

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de


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