View source: R/rounding_functions.R
roundup | R Documentation |
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.
roundup(x, numdigits = 0)
x |
a numeric vector. |
numdigits |
positive integer indicating the number of decimal places to be used. |
numeric vector of x
rounded to the number of digits specified
by numdigits
.
round
for base rounding function.
Other Rounding functions:
roundpow()
# 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)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.