Last active
November 5, 2021 22:26
-
-
Save sotoattanito/8e6fad4b7322ceae9f14f342985f1681 to your computer and use it in GitHub Desktop.
Round half up in R.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
round.off <- function (x, digits=0) | |
{ | |
posneg = sign(x) | |
z = trunc(abs(x) * 10 ^ (digits + 1)) / 10 | |
z = floor(z * posneg + 0.5) / 10 ^ digits | |
return(z) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference web site.
https://en.wikipedia.org/wiki/Rounding#Round_half_up