Description Usage Arguments Details Value Examples
This function is primarily geared towards use in labelling. By default it will
round a numeric vector to the lowest number of digits required to make sure
that no two values get rounded to the same value.
Alternatively it will round to significant digits, significant relative to
the range
of the input vector.
1 | round_sensibly(.x, .digits = 0, .separation = TRUE)
|
.x |
Numeric vector. Values to be rounded. |
.digits |
Numeric vector. Number of digits that should be rounded to
relative to the base value decided by |
.separation |
Logical scalar. If |
The usage of .digits
is not quite consistent between .separation = TRUE
and .separation = FALSE
. But it was chosen this way because it corresponds
in my experience with the way we think about rounding numbers for labels.
Either you want "x significant digits" as in digits that make actually a difference. It makes sense that 1 should be one significant digit and so on.
Or you want enough digits so that there are no identical labels. In this case it makes sense that 0 should be that number of digits.
A rounded numeric vector.
1 2 3 4 5 6 7 8 9 10 | x <- c(1.123, 1.134, 2.23)
# rounded to just enough digits to be able to separate one and 2
round_sensibly(x)
# rounded to one more digit
round_sensibly(x, 1)
# rounded to 1 significant digit of separation.
round_sensibly(x, 1, .separation = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.