round2 {numform} | R Documentation |
Rounding
Description
round2
- By default R's round
function uses the 'round half to
even' method. This function (taken from https://stackoverflow.com/a/12688836/1000343)
rounds half up.
round_any
- This tooling lets you round to fractional values, not
just whole numbers. Code adapted from https://stackoverflow.com/a/8665247/1000343.
Usage
round2(x, digits = 0, ...)
round_any(x, accuracy, f = round2, ...)
Arguments
x |
A vector of digits. |
digits |
The number of decimal places to round to. |
accuracy |
Number to round to. |
f |
A function to round (e.g., |
... |
ignored. |
Value
round2
- Returns numeric vector half rounded up.
round_any
- Returns a numeric vector or rounded fractional values.
Author(s)
Kohske Takahashi
References
https://stackoverflow.com/a/12688836/1000343
https://stackoverflow.com/a/8665247/1000343
Examples
data.frame(
orig = .5 + (0:8),
round = round(.5 + (0:8)),
round2 = round2(.5 + (0:8))
)
round_any(c(.123, 1.234, 4, 4.715), .5)
round_any(c(.123, 1.234, 4, 4.715), .25)
[Package numform version 0.7.0 Index]