num_result | R Documentation |
num_result
creates a list summarizing numeric values with rounding and tolerance.
It returns the original values, rounded values, the digits used, and the tolerance.
The rounding is done with the internal function fmt()
(similar to exams::fmt()
).
Users can pass additional arguments to fmt()
via ...
.
x
: original numeric values
fx
: rounded values as character (via fmt()
)
tolerance
: numeric tolerance for comparison
digits
: digits used for rounding
If digits
is not provided:
If length(x) > 1
, ceiling(-log10(min(diff(sort(x)), na.rm = TRUE)))
is used.
If length(x) == 1
, 3 + ceiling(-log10(abs(x)))
is used.
If tolerance
is not provided, it defaults to tolmult * 10^(1 - digits)
.
int_result()
is a shortcut for integer values (digits = 0
, tolerance = 0.1
).
num_result(x, digits = NULL, tolerance = NULL, tolmult = 2, ...)
int_result(x, ...)
num_res(x, digits = NULL, tolerance = NULL, tolmult = 2, ...)
int_res(x, ...)
x |
numeric: the input values |
digits |
numeric: number of digits to round to (default: |
tolerance |
numeric: optional numeric tolerance (default: |
tolmult |
numeric: multiplier for tolerance calculation (default: 2) |
... |
further arguments passed to
|
A list with elements x
, fx
, tolerance
, and digits
.
# Example: numeric values
x <- rnorm(10, mean = 1.8, sd = 0.25)
num_result(c(mean(x), x), digits = 2)
# Example: integer result
int_result(mean(x))
# Example: different digits and tolerance
num_result(pi, 3)
num_result(pi, 6)
num_result(pi, 6, tolmult = 5)
num_result(pi, 6, tolmult = 5, tolerance = 1e-6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.