Learn R Programming

table1 (version 1.4.3)

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

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, NMISS 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

stats.apply.rounding(
  x,
  digits = 3,
  digits.pct = 1,
  round.median.min.max = TRUE,
  round.integers = TRUE,
  round5up = TRUE,
  rounding.fn = signif_pad,
  ...
)

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.

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.

See Also

signif_pad stats.default

Examples

Run this code
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)

Run the code above in your browser using DataLab