Skip to contents

Summarise the distribution of random draws in an rvec, using means, medians, or modes.

Usage

draws_median(x, na_rm = FALSE)

# S3 method for class 'rvec_chr'
draws_median(x, na_rm = FALSE)

# S3 method for class 'rvec'
draws_median(x, na_rm = FALSE)

draws_mean(x, na_rm = FALSE)

# S3 method for class 'rvec'
draws_mean(x, na_rm = FALSE)

# S3 method for class 'rvec_chr'
draws_mean(x, na_rm = FALSE)

draws_mode(x, na_rm = FALSE)

# S3 method for class 'rvec'
draws_mode(x, na_rm = FALSE)

Arguments

x

An object of class rvec.

na_rm

Whether to remove NAs before calculating summaries. Default is FALSE.

Value

A vector.

Details

When method is "mode", reduce_rvec() returns the most common value for each observation. When there is a tie, it returns NA.

See also

Apply pre-specified functions across draws:

Apply arbitrary function across draws:

For additional functions for summarising random draws, see tidybayes and ggdist. Function as_list_col() converts rvecs into a format that tidybayes and ggdist can work with.

Examples

m <- rbind(a = c(1, 1, 1, 2, 3),
           b = c(2, 4, 0, 2, 3),
           c = c(0, 0, 1, 0, 100))
x <- rvec(m)
x
#> <rvec_dbl<5>[3]>
#>            a            b            c 
#>   1 (1, 2.9) 2 (0.2, 3.9)    0 (0, 90) 
draws_median(x)
#> a b c 
#> 1 2 0 
draws_mean(x)
#>    a    b    c 
#>  1.6  2.2 20.2 
draws_mode(x)
#> a b c 
#> 1 2 0