Learn R Programming

qwraps2 (version 0.6.1)

mean_se: Mean and Standard Error (of the mean)

Description

A function for calculating and formatting means and standard deviations.

Usage

mean_se(
  x,
  digits = getOption("qwraps2_frmt_digits", 2),
  na_rm = FALSE,
  show_n = "ifNA",
  denote_sd = "pm",
  markup = getOption("qwraps2_markup", "latex"),
  ...
)

Value

a character vector of the formatted values

Arguments

x

a numeric vector

digits

digits to the right of the decimal point to return in the percentage estimate.

na_rm

if true, omit NA values

show_n

defaults to "ifNA". Other options are "always" or "never".

denote_sd

a character string set to either "pm" or "paren" for reporting 'mean \(\pm\) sd' or 'mean (sd)'

markup

latex or markdown

...

pass through

Details

Given a numeric vector, mean_se will return a character string with the mean and standard error of the mean. Formatting of the output will be extended in future versions.

Examples

Run this code
set.seed(42)
x <- rnorm(1000, 3, 4)
mean(x)
sd(x) / sqrt(length(x)) # standard error
mean_se(x)
mean_se(x, show_n = "always")
mean_se(x, show_n = "always", denote_sd = "paren")

x[187] <- NA
mean_se(x, na_rm = TRUE)

Run the code above in your browser using DataLab