roundpow: Rounding to a Power of 10

View source: R/rounding_functions.R

roundpowR Documentation

Rounding to a Power of 10

Description

roundpow is a function that allows for traditional rounding of numbers to a power of 10. 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. The function roundup in this package allows one to apply the traditinal rounding measure. This function extends roundup by allowing one to round numbers to a power of 10.

Usage

roundpow(x, power = 1)

Arguments

x

a numeric vector.

power

positive integer indicating the power of ten to round too.

Value

numeric vector of x rounded to the power of 10 specified by power.

See Also

Other Rounding functions: roundup()

Examples

# Examples
roundpow(125, power=1)
roundpow(125, power=2)
roundpow(10555, power=1)
roundpow(10555, power=2)
roundpow(10555, power=3)
roundpow(10555, power=4)
# Comparing IEEE Rounding vs. Traditional Rounding
data(BSB)
IEEE <- with(BSB, round(TL / 10) * 10)
Trad <- with(BSB, roundpow(TL, 1))
plot(Trad ~ jitter(IEEE), xlab = "IEEE Total Length (mm)",
 ylab = "Traditional Total Length (mm)")

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