Learn R Programming

rvec (version 0.0.7)

draws_fun: Apply Summary Function Across Random Draws

Description

Summarise the distribution of random draws in an rvec, using a function.

Usage

draws_fun(x, fun, ...)

# S3 method for rvec draws_fun(x, fun, ...)

Value

The results from calls to fun, combined using vctrs::vec_c().

Arguments

x

An object of class rvec.

fun

A function.

...

Additional arguments passed to fun.

See Also

Apply pre-specified functions across draws:

  • draws_all()

  • draws_any()

  • draws_ci()

  • draws_min()

  • draws_max()

  • draws_median()

  • draws_mean()

  • draws_mode()

  • draws_quantile()

Examples

Run this code
set.seed(0)
m <- rbind(a = rnorm(100, mean = 5, sd = 2),
           b = rnorm(100, mean = -3, sd = 3),
           c = rnorm(100, mean = 0, sd = 20))
x <- rvec(m)
x
draws_fun(x, fun = mad)
draws_fun(x, fun = range)
draws_fun(x, weighted.mean, wt = runif(100))
draws_fun(x, function(x) sd(x) / mean(x))

Run the code above in your browser using DataLab