mcapply: Apply Functions Over mc or mcnode Objects

View source: R/mcapply.R

mcapplyR Documentation

Apply Functions Over mc or mcnode Objects

Description

Apply a function on all values or over a given dimension of an ‘⁠mcnode⁠’ object. May be used for all ‘⁠mcnode⁠’ objects of an ‘⁠mc⁠’ object.

Usage

mcapply(x, margin = c("all", "var", "unc", "variates"), fun, ...)

Arguments

x

a ‘⁠mc⁠’ or a ‘⁠mcnode⁠’ object.

margin

the dimension on which to apply the function. May be ‘⁠"all"⁠’ (default) to apply the function on all values, ‘⁠"var"⁠’ to apply on the variability dimension, ‘⁠"unc"⁠’ to apply on the uncertainty dimension, or ‘⁠"variates"⁠’ to apply on the variates. Note: do not use ‘⁠"var"⁠’ for ‘⁠"variates"⁠’.

fun

the function to be applied. When applied to a vector of length ‘⁠n⁠’, ‘⁠fun⁠’ should return a vector of length ‘⁠n⁠’ or ‘⁠1⁠’.

...

optional arguments to ‘⁠fun⁠’.

Value

If ‘⁠fun⁠’ returns a vector of length ‘⁠n⁠’ or if ‘⁠margin="all"⁠’, the returned ‘⁠mcnode⁠’s have the same type and dimension as ‘⁠x⁠’. Otherwise, the type of ‘⁠mcnode⁠’ is changed accordingly.

See Also

apply, mc, mcnode.

Examples

data(total)
xVUM
mcapply(xVUM, "unc", sum)
mcapply(xVUM, "var", sum)
mcapply(xVUM, "all", sum)
mcapply(xVUM, "variates", sum)
mcapply(total, "all", exp)

mc2d documentation built on Oct. 23, 2026, 1:06 a.m.