roundr | R Documentation |
Improved rounding formatter.
roundr(
x,
digits = 1L,
format = TRUE,
check = TRUE,
scipen = getOption("scipen")
)
## Default S3 method:
roundr(
x,
digits = 1L,
format = TRUE,
check = TRUE,
scipen = getOption("scipen")
)
## S3 method for class 'matrix'
roundr(
x,
digits = 1L,
format = TRUE,
check = TRUE,
scipen = getOption("scipen")
)
## S3 method for class 'data.frame'
roundr(
x,
digits = 1L,
format = TRUE,
check = TRUE,
scipen = getOption("scipen")
)
x |
numeric vector, matrix, or data frame |
digits |
number of digits past the decimal point to keep |
format |
logical; if |
check |
logical; if |
scipen |
see |
Uses sprintf
to round numeric value while keeping
trailing zeros.
An object having the same class as x
.
round
; Round
; sprintf
;
round_to
; pvalr
## compare
round(0.199, 2)
roundr(0.199, 2)
round(1e9)
roundr(1e9, 0)
roundr(1e9, 0, scipen = 10)
## drops negative when x rounds to 0, eg, case 1:
roundr(c(1000, 1, -0.0002, 0.0002, 0.5, -0.5, -0.002), digits = 3)
## for matrices or data frames (including factors and/or characters)
roundr(matrix(1:9, 3))
dd <- within(head(mtcars), {
mpg <- as.character(mpg)
cyl <- factor(cyl, labels = LETTERS[1:3])
})
roundr(dd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.