round_ceiling()
, round_floor()
, and round_trunc()
generalize
the base R functions ceiling()
, floor()
, and trunc()
, and
include them as special cases: With the default value for digits
, 0,
these round_*
functions are equivalent to their respective base
counterparts.
The last round_*
function, round_anti_trunc()
, generalizes another
function presented here: anti_trunc()
works like trunc()
except it
moves away from 0, rather than towards it. That is, whereas trunc()
minimizes the absolute value of x
(as compared to the other rounding
functions), anti_trunc()
maximizes it. anti_trunc(x)
is therefore equal
to trunc(x)
+ 1
if x
is positive, and to trunc(x) - 1
if x
is
negative.
round_anti_trunc()
, then, generalizes anti_trunc()
just as
round_ceiling()
generalizes ceiling()
, etc.
Moreover, round_trunc()
is equivalent to round_floor()
for positive
numbers and to round_ceiling()
for negative numbers. The reverse is again
true for round_anti_trunc()
: It is equivalent to round_ceiling()
for
positive numbers and to round_floor()
for negative numbers.