Description Usage Arguments Value Author(s) See Also Examples
A utility function to round numbers to a specified number of significant digits. Zeros are kept if they are significant.
1 | signif.pad(x, digits = 3, round.integers = FALSE)
|
x |
A numeric vector. |
digits |
An interger specifying the number of significant digits to keep. |
round.integers |
Should rounding be limited to digits to the right of the decimal point? |
A character vector containing the rounded numbers.
Ben Rich <benjamin.rich@certara.com>
signif
formatC
prettyNum
format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | x <- c(0.9001, 12345, 1.2, 1., 0.1)
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.