smart_round | R Documentation |
Function to round numerical values with minimal information loss (e.g. to avoid "0.000" values in tables).
smart_round(x, rnd = 0, return_char = TRUE)
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. |
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.
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
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.