niceRound: Rounding to a Predictable Number of Digits

Description Usage Arguments Details Author(s) See Also

Description

Rounds numbers to always have the specified number of decimal digits, rather than R's "greedy" most-compact rounding convention. Includes optional "<0.0..." override adequate for representing small p-values.

Usage

1
niceRound(numbers, digits = 0, plurb = FALSE)

Arguments

numbers

the numbers to be rounded. Can also be a vector or numeric array.

digits

the desired number of decimal digits

plurb

logical, should the p-value-style "less-than blurb" convention be used? Default FALSE.

Details

R's standard round utility rounds to at most the number of digits specified. When the number happens to round more "compactly", it rounds to fewer digits. Thus, for example, round(4.03,digits=2) yields 4 as an answer. This is undesirable when trying to format a table, e.g., for publication.

niceRound solves this problem by wrapping a format call around the round call. The result will always have digits decimal digits. In addition, since reporting p-values always involves rounding, if the argument plurb is TRUE, then values below the rounding thresholds will be represented using the "less than" convention. For example, with digits=3 and plurb=TRUE, the number 0.0004 will be represented as <0.001.

Author(s)

Assaf P. Oron <assaf.oron.at.seattlechildrens.org>

See Also

round,format


table1xls documentation built on May 2, 2019, 5:54 a.m.