fsignif {dreamerr} | R Documentation |
Formatting numbers with display of significant digits
Description
Formatting of numbers, when they are to appear in messages. Displays only significant digits in a "nice way" and adds commas to separate thousands. It does much less than the format
function, but also a bit more though.
Usage
fsignif(x, s = 2, r = 0, commas = TRUE)
signif_plus
Arguments
x |
A numeric vector. |
s |
The number of significant digits to be displayed. Defaults to 2. All digits not in the decimal are always shown. |
r |
For large values, the number of digits after the decimals to be displayed (beyond the number of significant digits). Defaults to 0. It is useful to suggest that a number is not an integer. |
commas |
Whether or not to add commas to separate thousands. Defaults to |
Format
An object of class function
of length 1.
Value
It returns a character vector of the same length as the input.
Examples
x = rnorm(1e5)
x[sample(1e5, 1e4, TRUE)] = NA
# Dumb function telling the number of NA values
tell_na = function(x) message("x contains ", fsignif(sum(is.na(x))), " NA values.")
tell_na(x)
# Some differences with signif:
show_diff = function(x, d = 2) cat("signif(x, ", d, ") -> ", signif(x, d),
" vs fsignif(x, ", d, ") -> ",
fsignif(x, d), "\n", sep = "")
# Main difference is for large numbers
show_diff(95123.125)
show_diff(95123.125, 7)
# Identical for small numbers
show_diff(pi / 500)
[Package dreamerr version 1.4.0 Index]