signif_pad {table1} | R Documentation |
Round numbers with 0-padding.
Description
Utility functions to round numbers, similar the the base functions signif
and round
, but resulting in character representations that keep zeros at
the right edge if they are significant.
Usage
signif_pad(x, digits = 3, round.integers = TRUE, round5up = TRUE, dec, ...)
round_pad(x, digits = 2, round5up = TRUE, dec, ...)
Arguments
x |
A numeric vector. |
digits |
An integer specifying the number of significant digits to keep
(for |
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 |
dec |
The character symbol to use as decimal mark (locale
specific). [Deprecated; use |
... |
Further options, passed to |
Value
A character vector containing the rounded numbers.
See Also
signif
round
formatC
prettyNum
format
Examples
x <- c(0.9001, 12345, 1.2, 1., 0.1, 0.00001 , 1e5)
signif_pad(x, digits=3)
signif_pad(x, digits=3, round.integers=TRUE)
# Compare:
as.character(signif(x, digits=3))
format(x, digits=3, nsmall=3)
prettyNum(x, digits=3, drop0trailing=TRUE)
prettyNum(x, digits=3, drop0trailing=FALSE)
# This is very close.
formatC(x, format="fg", flag="#", digits=3)
formatC(signif(x, 3), format="fg", flag="#", digits=3)
# Could always remove the trailing "."
sub("[.]$", "", formatC(x, format="fg", flag="#", digits=3))