gmGeostats (version 0.10-6)

gmApply: Apply Functions Over Array or DataFrameStack Margins

Description

Returns a vector or array or list of values obtained by applying a function to the margins of an array or matrix. Method gmApply.default() is just a wrapper on base::apply(). Method gmApply() reimplements the functionality with future access to parallel computing and appropriate default values for the MARGIN. ALWAYS use named arguments here!

Usage

gmApply(X, ...)

# S3 method for default gmApply(X, MARGIN, FUN, ...)

# S3 method for DataFrameStack gmApply(X, MARGIN = stackDim(X), FUN, ..., .parallel = FALSE)

Arguments

X

a DataFrameStack() object (see base::apply() for other options)

...

further arguments to FUN

MARGIN

a name or an index of the dimension along which should the calculations be done; defaults to the stacking dimension of the DataFrameStack(), i.e. to the output of stackDim(X)

FUN

function to apply; the default behaviour being that this function is applied to each element of the stack X

.parallel

currently ignored

Value

In principle, if MARGIN==stackDim(X) (the default), the oputput is a list with the result of using FUN on each element of the stack. If FUN returns a matrix or a data.frame assimilable to one element of the stack, a transformation of this output to a DataFrameStack is attempted.

For X non-DataFrameStack or MARGIN!=stackDim(X) see base::apply().

Methods (by class)

  • default: wrapper around base::apply()

  • DataFrameStack: Apply Functions Over DataFrameStack Margins

Examples

Run this code
# NOT RUN {
dm = list(point=1:100, var=LETTERS[1:2], rep=paste("r",1:5, sep=""))
ar = array(rnorm(1000), dim=c(100,2,5), dimnames = dm)
dfs = DataFrameStack(ar, stackDim="rep")
gmApply(dfs, FUN=colMeans)
rs = gmApply(dfs, FUN=function(x) x+1)
class(rs)
getStackElement(rs,1)
getStackElement(dfs,1)
# }

Run the code above in your browser using DataLab