rep_mean_sd {kdry}R Documentation

rep_mean_sd

Description

Reporting helper function: computes and formats mean and standard deviation from a numeric vector.

Usage

rep_mean_sd(
  x,
  digits = 2,
  na.rm = TRUE,
  sd_brackets = c("round", "square"),
  sd_prefix = TRUE,
  weighted = FALSE,
  weights = NA
)

Arguments

x

A numeric vector.

digits

An integer indicating the number of decimal places.

na.rm

A logical indicating if missings should be removed from x before computing the distributional parameters (default: TRUE).

sd_brackets

A character. Either "round" (default) or "square" to indicate the type of brackets to surround the standard deviation in the formatted output.

sd_prefix

A logical. If TRUE (default), the standard deviation is prefixed with a plus-minus-sign ("±").

weighted

A logical. If TRUE, a weighted mean and standard deviation are calculated (default: FALSE).

weights

A vector with the weights (if weighted = TRUE; default: NA) passed futher on to stats::weighted.mean() and Hmisc::wtd.var().

Value

A character with the formatted output.

See Also

mean(), stats::sd(), stats::weighted.mean(), Hmisc::wtd.var()

Examples

set.seed(123)
x <- rnorm(1000)
rep_mean_sd(x)
rep_mean_sd(rep(1, 10))
rep_mean_sd(x, sd_brackets = "square")
rep_mean_sd(x, sd_brackets = "square", sd_prefix = FALSE)


[Package kdry version 0.0.2 Index]