stats.apply.rounding: Apply rounding to basic descriptive statistics.

Description Usage Arguments Value See Also Examples

View source: R/table1.R

Description

Not all statistics should be rounded in the same way, or at all. This function will apply rounding selectively to a list of statistics as returned by stats.default. In particular we don't round counts (N and FREQ), and for MIN, MAX and MEDIAN the digits is interpreted as the minimum number of significant digits, so that we don't loose any precision. Percentages are rounded to a fixed number of decimal places (default 1) rather than a specific number of significant digits.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
stats.apply.rounding(
  x,
  digits = 3,
  digits.pct = 1,
  round.median.min.max = TRUE,
  round.integers = TRUE,
  round5up = TRUE,
  rounding.fn = signif_pad,
  ...
)

Arguments

x

A list, such as that returned by stats.default.

digits

An integer specifying the number of significant digits to keep.

digits.pct

An integer specifying the number of digits after the decimal place for percentages.

round.median.min.max

Should rounding applied to median, min and max?

round.integers

Should rounding be limited to digits to the right of the decimal point?

round5up

Should numbers with 5 as the last digit always be rounded up? The standard R approach is "go to the even digit" (IEC 60559 standard, see round), while some other softwares (e.g. SAS, Excel) always round up.

rounding.fn

The function to use to do the rounding. Defaults to signif_pad.

...

Further arguments.

Value

A list with the same number of elements as x. The rounded values will be character (not numeric) and will have 0 padding to ensure consistent number of significant digits.

See Also

signif_pad stats.default

Examples

1
2
3
4
x <- round(exp(rnorm(100, 1, 1)), 6)
stats.default(x)
stats.apply.rounding(stats.default(x), digits=3)
stats.apply.rounding(stats.default(round(x, 1)), digits=3)

table1 documentation built on June 7, 2021, 1:07 a.m.