ApplyTime: Apply a function across time

Description Usage Arguments Value Author(s) Source Examples

View source: R/apply-fields.R

Description

Apply a function across the temporal dimension of a "pField" or "pTs" object by using apply on the columns of the object. Depending on the output of the applied function, this gives a "pField" or "pTs" object with only one, or with several time steps.

Usage

1
ApplyTime(data, FUN, newtime = NULL, ...)

Arguments

data

a "pField" or "pTs" object.

FUN

the function to be applied.

newtime

the observation time point(s) of the result. For NULL (the default), the average of the time points in data is used, if the applied function yields an aggregated result (i.e. one time step), and the original time points in data if the result has as many time steps as the input data. For other cases, you need to provide the respective new time axis here.

...

further arguments passed on to FUN.

Value

a "pField" or "pTs" object with the results of the function applied.

Author(s)

Thomas Laepple

Source

Function copied from "basis.R" in paleolibary/src/.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- pField(data = array(rnorm(10 * 10 * 100), dim = c(10, 10, 100)),
            time = 1 : 100, lat = 1 : 10, lon = 1 : 10)
y <- ApplyTime(x, mean)

# subset incompletely to create a pTs object
x.pts <- x[, 1 : 15]
y.pts <- ApplyTime(x.pts, mean) # is the same as y[, 1 : 15]

# you need to supply a new time axis e.g. for use cases such as
y <- ApplyTime(x, range, newtime = c(1, 2))

EarthSystemDiagnostics/pfields documentation built on Jan. 10, 2022, 10:37 p.m.