roundHalfUp {clinUtils} | R Documentation |
Round a number with 'rounding up' strategy for rounding off a 5
Description
This function rounds a number for a specified number of digits.
It rounds off to the highest number for a 5.
The default R round
function rounds to the
'even digit' in case of rounding off a 5
(see 'Details' section in ? round
).
This function instead rounds up to the nearest number for a 5.
It mimics a similar rounding strategy used in SAS.
See examples for the difference between round
and
'roundHalfUp' below.
Usage
roundHalfUp(x, digits = 0)
Arguments
x |
Numeric vector to round. |
digits |
Integer with number of digits to consider, 0 by default. |
Value
Rounded numeric vector.
Author(s)
stackoverflow question 6461209
Examples
# numbers are rounded to the closest even number in case of .5
# with the round 'base' function
round(0.45, 1)
# 'roundHalfUp' always round to the next highest number in case of .5
roundHalfUp(0.45, 1)
# rounding is the same for uneven number:
round(0.55, 1)
roundHalfUp(0.55)
# other examples
round(1.456e-2, digits = 3)
round(1.456e-2, digits = 2)
round(1.456e-2, digits = 1)
[Package clinUtils version 0.2.0 Index]