roundup: Rounding

View source: R/rounding_functions.R

roundupR Documentation

Rounding

Description

roundup is a function that allows for traditional rounding of numbers. The built in R rounding function (round) from the R base package follows the standard of the IEC 60559 when determining how to round off the number 5. This rule states that you 'go to the even digit'. This is different from how most people learn to round off 5 in school (and different from how Excel rounds numbers), with one rounding 5 off to the next highest absolute value integer. To illustrate the difference, where the base function rounds 0.5 and -2.5 to 0 and -2, respectively, roundup rounds 0.5 and -2 to 1 and -3, respectively.

Usage

roundup(x, numdigits = 0)

Arguments

x

a numeric vector.

numdigits

positive integer indicating the number of decimal places to be used.

Value

numeric vector of x rounded to the number of digits specified by numdigits.

See Also

round for base rounding function.

Other Rounding functions: roundpow()

Examples

# Examples
roundup(-2.25, numdigits=1)
round(.5 + -2:4) # IEEE rounding
roundup(.5+ -2:4) # Traditional rounding
# Comparing IEEE Rounding vs. Traditional Rounding
data(BSB)
IEEE <- with(BSB, round(TL / 10))
Trad <- with(BSB, roundup(TL / 10))
table(IEEE,Trad)
plot(Trad ~ jitter(IEEE), xlab = "IEEE Total Length (cm)",
 ylab = "Traditional Total Length (cm)")

ballengerj/FishyR documentation built on June 17, 2022, 10:33 p.m.