mcapply: Apply Functions Over mc or mcnode Objects

Description Usage Arguments Value See Also Examples

View source: R/mcapply.R

Description

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

Usage

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

Arguments

x

A mc or a mcnode object.

margin

The dimension on which applying the function. Maybe "all" (default) to apply the function on all values, "var" to apply the function on the variability dimension, "unc" to apply the function on the uncertainty dimension, or "variates" to apply the function on the variates. Watch out: 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.

...

Optionnal arguments to fun.

Value

If fun returns a function of length n or if margin="all", the returned mcnodes are of type and dimension of x. In other cases, the type of mcnode is changed.

See Also

apply, mc, mcnode.

Examples

1
2
3
4
5
6
7
data(total)
xVUM
mcapply(xVUM, "unc", sum)
mcapply(xVUM, "var", sum)
mcapply(xVUM, "all", sum)
mcapply(xVUM, "variates", sum)
mcapply(total, "all", exp)

Example output

Loading required package: mvtnorm

Attaching package: 'mc2d'

The following objects are masked from 'package:base':

    pmax, pmin

  node    mode nsv nsu nva variate     min  mean median   max Nas type outm
1    x numeric 101  51   2       1 0.00012 0.499  0.496 0.999   3   VU each
2    x numeric 101  51   2       2 0.00045 0.494  0.496 1.000   0   VU each
  node    mode nsv nsu nva variate  min mean median  max Nas type outm
1    x numeric 101   1   2       1 20.5 25.5   25.3 29.9   3    V each
2    x numeric 101   1   2       2 20.8 25.2   25.0 30.0   0    V each
  node    mode nsv nsu nva variate min mean median  max Nas type outm
1    x numeric   1  51   2       1  43 50.5   50.1 56.2   1    U each
2    x numeric   1  51   2       2  45 49.9   49.3 55.5   0    U each
  node    mode nsv nsu nva variate     min  mean median   max Nas type outm
1    x numeric 101  51   2       1 0.00012 0.499  0.496 0.999   3   VU each
2    x numeric 101  51   2       2 0.00045 0.494  0.496 1.000   0   VU each
  node    mode nsv nsu nva variate   min  mean median  max Nas type outm
1    x numeric 101  51   1       1 0.027 0.993   0.99 1.99   3   VU each
    node    mode nsv nsu nva variate  min mean median  max Nas type outm
1     x0 numeric   1   1   1       1 1.19 1.19   1.19 1.19   0    0 each
2     xV numeric 101   1   1       1 1.00 1.79   1.71 2.68   0    V each
3     xU numeric   1  51   1       1 1.06 1.63   1.54 2.71   0    U each
4    xVU numeric 101  51   1       1 1.00 1.72   1.64 2.72   0   VU each
5    x0M numeric   1   1   2       1 1.77 1.77   1.77 1.77   0    0 each
6    x0M numeric   1   1   2       2 1.08 1.08   1.08 1.08   0    0 each
7    xVM numeric 101   1   2       1 1.00 1.69   1.53 2.64   0    V each
8    xVM numeric 101   1   2       2 1.02 1.65   1.56 2.71   0    V each
9    xUM numeric   1  51   2       1 1.01 1.72   1.66 2.69   0    U each
10   xUM numeric   1  51   2       2 1.03 1.76   1.67 2.71   0    U each
11  xVUM numeric 101  51   2       1 1.00 1.72   1.64 2.72   3   VU each
12  xVUM numeric 101  51   2       2 1.00 1.71   1.64 2.72   0   VU each
13 xVUM3 numeric 101  51   2      NA 1.01 1.72   1.71 2.71   0   VU mean
14 xVUM3 numeric 101  51   2      NA 1.00 1.44   1.35 2.70   0   VU  min

mc2d documentation built on July 5, 2021, 3:01 p.m.