roundr-deprecated | R Documentation |
A simple rounding function that returns exactly the number of digits requested. Really just a wrapper for format and round.
Credit for this one goes to my buddy Kyle Hart. I had seen a few different versions of a function like this and I really like his for the flexibility that it offers by formatting as a character. In the end, I took his basic function and took it a few steps further to be the way that I want it to be, like the option to trim whitespace.
roundr(x, d, as_text, trim)
x |
a numeric vector. |
d |
integer indicating the number of decimal places (round). Negative values are allowed (see 'Examples'). |
as_text |
logical; if FALSE, a numeric value is returned; if TRUE, then
a character is returned with values aligned at the decimal point and padded
with spaces in front (use |
trim |
logical; if FALSE, logical, numeric and complex values are
right-justified to a common width; if TRUE the leading blanks for
justification are suppressed. Only has an effect if |
Rounding to a negative number of digits means rounding to a power of ten.
An object of similar structure to x
lamisc-deprecated
numbers <- c(0.0018, 0.1234, 12.6978, -86.75309, 264.4445, -99.9999)
roundr(numbers, d = 2, as_text = TRUE)
roundr(numbers, d = 2, as_text = TRUE, trim = TRUE)
roundr(numbers, d = 2, as_text = FALSE)
roundr(numbers, d = -2, as_text = FALSE)
roundr(numbers, d = -2, as_text = TRUE, trim = TRUE)
roundr(numbers, d = -2, as_text = TRUE, trim = FALSE)
numbers <- c(10.00001, 12345, 1234.5, NA, 1.2345, 0.12345)
roundr(numbers, d = 2, as_text = TRUE)
roundr(numbers, d = 2, as_text = TRUE, trim = TRUE)
roundr(numbers, d = 2, as_text = FALSE)
roundr(numbers, d = -2, as_text = FALSE)
roundr(numbers, d = -2, as_text = TRUE, trim = TRUE)
roundr(numbers, d = -2, as_text = TRUE, trim = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.