Description Usage Arguments Value Examples
View source: R/utility_functions.R
A function to compute nicely formatted common summary statistics.
1 | commonStats(x, type = "M (SD)", digits = 1, pad_left = NULL, na.rm = T)
|
x |
A vector of values. |
type |
The type of summary statistic to compute.
|
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 |
A character string.
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' )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.