This function computes the range of numeric values in a vector and adjusts
the bounds to "nice" rounded numbers. Specifically, it rounds the lower
bound downwards (similar to floor()
) and the upper bound upwards (similar
to ceiling()
) to the specified number of digits. This can be useful when
preparing data ranges for axis labels, plotting, or reporting. The function
returns a numeric vector of length two, containing the adjusted lower and
upper bounds.
Arguments
- x
A numeric vector to be bounded.
- digits
An integer scalar specifying the number of digits to round the bounds to. A positive value determines the number of decimal places used. A negative value rounds to the nearest 10, 100, etc. If
digits
isNULL
, no rounding is performed and the exact range is returned.- na_rm
A logical flag indicating whether
NA
values should be removed before computing the range. IfTRUE
, the range is computed from non-NA
values only. IfFALSE
andx
contains anyNA
values, the function returnsc(NA, NA)
.