Skip to content

Instantly share code, notes, and snippets.

@sotoattanito
sotoattanito / roundoff.r
Last active November 5, 2021 22:26
Round half up in R.
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)
}