Newer
Older
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Apply.R
\name{Apply}
\alias{Apply}
Apply(data, margins = NULL, AtomicFun, ..., parallel = FALSE,
ncores = NULL)
\item{data}{A single numeric object (vector, matrix or array) or a list of numeric objects. They must be in the same order as expected by AtomicFun.}
\item{margins}{List of vectors containing the margins for the input objects to be split by. Or, if there is a single vector of margins specified and a list of objects in data, then the single set of margins is applied over all objects.}
\item{AtomicFun}{Function to be applied to the arrays.}
\item{...}{Additional arguments to be used in the AtomicFun.}
\item{parallel}{Logical, should the function be applied in parallel.}
\item{ncores}{The number of cores to use for parallel computation.}
}
\value{
When using a single numeric object as input, Apply is almost identical to the apply function. For multiple input objects, the output array
will have dimensions equal to the dimensions specified in 'margins'.
}
\details{
A user can apply a function that receives 1 or more numeric objects as input, each with a different number of dimensions, and returns as a result a single array with any number of dimensions.
#Change in the rate of exceedance for two arrays, with different
#dimensions, for some matrix of exceedances.
data = list(array(rnorm(2000), c(10,10,20)), array(rnorm(1000), c(10,10,10)),
array(rnorm(100), c(10, 10)))
test_fun <- function(x, y, z) {((sum(x > z) / (length(x))) /
(sum(y > z) / (length(y)))) * 100}
margins = list(c(1, 2), c(1, 2), c(1,2))
test <- Apply(data, margins, AtomicFun = "test_fun")
}
\references{
Wickham, H (2011), The Split-Apply-Combine Strategy for Data Analysis, Journal of Statistical Software.
}