gmApply {gmGeostats} | R Documentation |
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, ...)
## Default S3 method:
gmApply(X, MARGIN, FUN, ...)
## S3 method for class 'DataFrameStack'
gmApply(X, MARGIN = stackDim(X), FUN, ..., .parallel = FALSE)
Arguments
X |
a |
... |
further arguments to |
MARGIN |
a name or an index of the dimension along which should
the calculations be done; defaults to the stacking dimension of the
|
FUN |
function to apply; the default behaviour being that this function
is applied to each element of the stack |
.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 aroundbase::apply()
-
DataFrameStack
: Apply Functions Over DataFrameStack Margins
Examples
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)