Priority:
If sdig is provided, round x to that many significant digits.
If sdig is NULL but ref is provided, infer the number of significant digits from ref.
If both are NULL, return x unchanged.
Usage
round_like(x, ref = NULL, sdig = NULL)
Arguments
- x
Numeric vector to round.
- ref
Optional numeric vector used to infer the number of significant digits.
- sdig
Optional integer specifying the number of significant digits to apply.
Value
A numeric vector rounded to the appropriate precision.
Examples
round_like(123.456, sdig = 2) # -> 120
#> [1] 120
round_like(123.456, ref = 12.3) # -> 123
#> [1] 123
round_like(123.456, ref = 12.34) # -> 123.5
#> [1] 123.5
round_like(123.456) # -> 123.456
#> [1] 123.456