num_result: Numeric Rounding List

num_resultR Documentation

Numeric Rounding List

Description

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).

Usage

num_result(x, digits = NULL, tolerance = NULL, tolmult = 2, ...)

int_result(x, ...)

num_res(x, digits = NULL, tolerance = NULL, tolmult = 2, ...)

int_res(x, ...)

Arguments

x

numeric: the input values

digits

numeric: number of digits to round to (default: NULL)

tolerance

numeric: optional numeric tolerance (default: NULL)

tolmult

numeric: multiplier for tolerance calculation (default: 2)

...

further arguments passed to fmt(). Common arguments include:

  • digits: number of digits for formatting

  • zeros: logical; pad with trailing zeros (default TRUE for digits < 4)

Value

A list with elements x, fx, tolerance, and digits.

Examples

# 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)

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.