smart_round {SUNGEO} | R Documentation |
Smart numerical rounding function
Description
Function to round numerical values with minimal information loss (e.g. to avoid "0.000" values in tables).
Usage
smart_round(x, rnd = 0, return_char = TRUE)
Arguments
x |
Vector of values to be rounded. Numeric. |
rnd |
Requested number of decimal places. Default is 0. Non-negative integer. |
return_char |
Return rounded values as character string? Default is TRUE. Logical. |
Details
Rounds the values in its first argument to the specified number of decimal places (default 0). If brute-force rounding produces zero values (e.g. "0.00"), the number of decimal places is expanded to include the first significant digit.
Value
If return_char=TRUE
, returns a character string of same length as x
. If return_char=FALSE
, returns a numerical vector of same length as x
.
Examples
# Round a vector of numbers, character string output (best for tables)
## Not run:
out_1 <- smart_round(c(.0013,2.3,-1,pi),rnd=2)
out_1
## End(Not run)
# Round a vector of numbers, numerical output
## Not run:
out_2 <- smart_round(c(.0013,2.3,-1,pi),rnd=2,return_char=FALSE)
out_2
## End(Not run)
[Package SUNGEO version 1.3.0 Index]