fmt_mean_sd: Formatted mean and standard deviation

Description Usage Arguments Details Value See Also Examples

View source: R/helpers.R

Description

A function to calculate and format a mean and standard deviation.

Usage

1
fmt_mean_sd(x, format = "%.1f")

Arguments

x

The input data vector or data frame column.

format

A formatting string suitable for input into the sprintf function. By default, this format is defined as "%.1f", which displays the mean and standard deviation with one decimal place.

Details

This function calculates a mean and standard deviation, and formats using sprintf. You may control the format using the format parameter. Function will ignore NA values in the input data. Results are returned as a character vector.

Value

The formatted mean and standard deviation.

See Also

Other helpers: fmt_cnt_pct(), fmt_median(), fmt_n(), fmt_quantile_range(), fmt_range()

Examples

1
2
3
4
5
6
7
v1 <- c(4.3, 3.7, 8.7, 6.1, 9.2, 5.6, NA, 0.7, 7.8, 4.9)

# Format mean and standard deviation
fmt_mean_sd(v1)

# Output
# "5.7 (2.7)"

fmtr documentation built on June 21, 2021, 9:06 a.m.