Format a numeric vector in a tibble
Constructs a numeric vector that can be formatted with predefined significant digits, or with a maximum or fixed number of digits after the decimal point. Scaling is supported, as well as forcing a decimal, scientific or engineering notation. If a label is given, it is shown in the header of a column.
set_num_opts()
adds formatting options to an arbitrary numeric vector,
useful for composing with other types.
num( x, ..., sigfig = NULL, digits = NULL, label = NULL, scale = NULL, notation = c("fit", "dec", "sci", "eng", "si"), fixed_exponent = NULL ) set_num_opts( x, ..., sigfig = NULL, digits = NULL, label = NULL, scale = NULL, notation = c("fit", "dec", "sci", "eng", "si"), fixed_exponent = NULL )
x |
A numeric vector. |
... |
These dots are for future extensions and must be empty. |
sigfig |
Define the number of significant digits to show. Must be one or greater.
The |
digits |
Number of digits after the decimal points to show.
Positive numbers specify the exact number of digits to show.
Negative numbers specify (after negation) the maximum number of digits to show.
With |
label |
A label to show instead of the type description. |
scale |
Multiplier to apply to the data before showing.
Useful for displaying e.g. percentages.
Must be combined with |
notation |
One of
|
fixed_exponent |
Use the same fixed_exponent for all numbers in scientific, engineering or SI notation.
|
Other vector classes:
char()
# Display as a vector num(9:11 * 100 + 0.5) # Significant figures tibble::tibble( x3 = num(9:11 * 100 + 0.5, sigfig = 3), x4 = num(9:11 * 100 + 0.5, sigfig = 4), x5 = num(9:11 * 100 + 0.5, sigfig = 5), ) # Maximum digits after the decimal points tibble::tibble( x0 = num(9:11 * 100 + 0.5, digits = 0), x1 = num(9:11 * 100 + 0.5, digits = -1), x2 = num(9:11 * 100 + 0.5, digits = -2), ) # Use fixed digits and a currency label tibble::tibble( usd = num(9:11 * 100 + 0.5, digits = 2, label = "USD"), gbp = num(9:11 * 100 + 0.5, digits = 2, label = "£"), chf = num(9:11 * 100 + 0.5, digits = 2, label = "SFr") ) # Scale tibble::tibble( small = num(9:11 / 1000 + 0.00005, label = "%", scale = 100), medium = num(9:11 / 100 + 0.0005 , label = "%", scale = 100), large = num(9:11 / 10 + 0.005 , label = "%", scale = 100) ) # Notation tibble::tibble( sci = num(10^(-13:6), notation = "sci"), eng = num(10^(-13:6), notation = "eng"), si = num(10^(-13:6), notation = "si"), dec = num(10^(-13:6), notation = "dec") ) # Fixed exponent tibble::tibble( scimin = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = -Inf), engmin = num(10^(-7:6) * 123, notation = "eng", fixed_exponent = -Inf), simin = num(10^(-7:6) * 123, notation = "si", fixed_exponent = -Inf) ) tibble::tibble( scismall = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = -3), scilarge = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = 3), scimax = num(10^(-7:6) * 123, notation = "sci", fixed_exponent = Inf) )
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.