format.nums: Format or print nice summaries of the median and IQR, the...

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

Format the median and interquartile range as either “median (Q1 to Q3)” or “median (Q1, Q3)”; format the median and range similarly; format the mean and SD as “mean (SD)”.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## S3 method for class 'medIQR'
format(x, digits = 2, format = "f", isep = " to ", ...)
## S3 method for class 'medIQR'
print(x, quote = FALSE, ...)
## S3 method for class 'medR'
format(x, digits = 2, format = "f", isep = " to ", ...)
## S3 method for class 'medR'
print(x, quote = FALSE, ...)
## S3 method for class 'meanSD'
format(x, digits = 2, format = "f", isep = " to ", ...)
## S3 method for class 'meanSD'
print(x, quote = FALSE, ...)

Arguments

x

The object to format or print.

digits

The number of digits to display. This is passed to formatC so details are to be found there. Briefly, whether digits is the number of significant digits or number of digits after the decimal point depends on the format argument. By default digits is the number of digits after the decimal place.

format

The style of formatting. This is passed to formatC so details are to be found there. When format = "f", the digits argument is interpreted as the number of digits after the decimal place. When format = "g" it is the number of significant digits.

isep

The interval separator, or how the quartiles should be separated. By default, the quartiles are separated by the word to as in “(Q1 to Q3)”. An alternative is to separate the quartiles with a comma as in “(Q1, Q3)”. These are both preferred to separating the quartiles with a dash which is easily confused with a negative sign.

quote

Logical, indicating whether or not strings should be printed with surrounding quotes.

...

Other arguments passed to formatC.

Details

The convention of many biomedical journals is to summarize a distribution using a shorthand notation of the form “median (IQR)” or “mean (SD)”. For example, some journal text might read “... the median (IQR) age of the treated group was 55 (32 to 81) ...” while a table stub might read “Age, median (IQR), years”. This function facilitates this shorthand.

Value

For univariate summaries, the formatted result is a character vector of length one. For conditional summaries as given by the formula method, the formatted result is a one-row matrix with informative dimnames. The print method returns x invisibly.

Note

Formatting and rounding floating point numbers is complicated. Important ideas are the number of significant digits versus number of decimal places to display, the round-to-even rule, and the fact that some numbers (even “simple” ones like like 0.15) cannot be represented exactly and thus may not be rounded or formatted as some users expect.

Author(s)

Stephen Weigand Weigand.Stephen@mayo.edu

See Also

medIQR, medR, and meanSD; formatC, format.

Examples

1
2
3
4
5
data(sleep)
meanSD(sleep$extra)
result <- medIQR(extra ~ group, data = sleep)
result # to print
format(result)

summarize documentation built on May 2, 2019, 6:51 p.m.