VectorizeM | R Documentation |
Build a wrapped function that applies to each unique argument in a vector of arguments once.
VectorizeM(
FUN,
vectorize.args = arg.names,
SIMPLIFY = TRUE,
USE.NAMES = TRUE,
UNLIST = FALSE
)
FUN |
function to apply |
vectorize.args |
a character vector of arguments which should be vectorized. Defaults to first argument of FUN. If set must be length 1. |
SIMPLIFY |
logical or character string; attempt to reduce the result to a vector, matrix or higher dimensional array; see the simplify argument of sapply. |
USE.NAMES |
logical; use names if the first ... argument has names, or if it is a character vector, use that character vector as the names. |
UNLIST |
logical; if TRUE try to unlist the result. |
Only sensible for pure side-effect free deterministic functions.
adapted function (vectorized with one call per different value).
Vectorize
, vapplym
, lapplym
fs <- function(x) { x <- x[[1]]; print(paste("see", x)); sin(x) }
fv <- VectorizeM(fs)
# should only print "see" twice, not 6 times
fv(c(0, 1, 1, 0, 0, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.