| mmapply {implicitExpansion} | R Documentation |
Apply a Function to Multiple Arrays with Implicit Expansion
Description
Similar function to mapply with support for implicit expansion.
Usage
mmapply(
FUN,
...,
MoreArgs = list(),
SIMPLIFY = TRUE,
USE.NAMES = TRUE,
ALLOW.RECYCLING = FALSE
)
Arguments
FUN |
Function to apply to each combination of arguments. Found via |
... |
Objects that are coerced to arrays, expanded using implicit expansion, and then vectorized over. |
MoreArgs |
Pass arguments in a list instead of |
SIMPLIFY |
If |
USE.NAMES |
If |
ALLOW.RECYCLING |
Whether to allow recycling of elements in each dimension. |
Details
Most arguments are handled in a similar fashion to mapply with some key differences:
Entries of
MoreArgsare treated the same as the ones in..., i.e.mmapply(...)is the same asmmapply(MoreArgs = list(...)). Additional arguments to FUN can be passed here or in..., either as they are (if they are atomic), or as alist()of length one.-
SIMPLIFYonly simplifies a list array to an atomic array, nothing else. -
USE.NAMESuses names from all arguments, but never uses an argument itself as names.
If ALLOW.RECYCLING is set to TRUE, all arrays of any size are compatible.
Value
An array containing the result of FUN for each combination of entries from ... after implicit expansion.
See Also
Examples
summaries <- list(Max = max, Min = min, avg = mean)
data <- list(a = 1:5, b = 2:3, c = 20:12)
formatStrings <- array(c('%.1f', '%.3f'), c(1,1,2))
mmapply(function(f, d, s) sprintf(s, f(d)), summaries, t(data), formatStrings)