commonStats: Common Summary Statistics

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

A function to compute nicely formatted common summary statistics.

Usage

1
commonStats(x, type = "M (SD)", digits = 1, pad_left = NULL, na.rm = T)

Arguments

x

A vector of values.

type

The type of summary statistic to compute.

  • 'M (SD)' or 'M = A, SD = B' for mean and standard deviation.

  • 'Md (IQR)' for median and inter-quartile range.

  • 'F (%)' or '% (F)' for frequencies and percentages.

  • 'Q1 to Q3' or 'Q1 - Q3' or 'Q1 | Q3' for the 1st and third quartiles.

  • 'Mn to Mx' or 'Mn - Mx' or 'Mn | Mx' for the minimum and maximum.

  • 'A (%)' or 'A% (B)' for converting pre-computed values to nicely formatted frequencies and percentages.

  • 'A to B' or 'A - B' or 'A | B' for the range between to pre-computed values.

digits

The number of digits to round to.

pad_left

The minimum number of required characters. If the observed value is less than what is required, adds spaces to the left.

na.rm

Logical; if TRUE removes NA values.

Value

A character string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Mean and standard deviation
commonStats( rnorm( 100, 100, 15 ), type = 'M (SD)' )

# Median and inter-quartile range
commonStats( rgamma( 100 ), type = 'Md (IQR)' )

# Frequency and percentage
commonStats( rbinom( 100, 1, .2 ), type = 'F (%)' )
commonStats( rbinom( 100, 1, .2 ), type = '% (F)', digits = 0 )

# 1st and 3rd quartiles
commonStats( rnorm( 100 ), type = 'Q1 to Q3' )

# Minimum and maximum
commonStats( runif( 100, -4, 4 ), type = 'Mn to Mx' )

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.