round_up_nice | R Documentation |
round_up_nice
will examine a vector of numbers and round each upwards to a 'nice' value.
round_up_nice(x, nice = seq(1, 10))
x |
A data object. |
nice |
A numeric vector defining base values that the user believes are 'nice'. |
The function is vectorized so that multiple inputs can be examined without having to define any specific loops.
When defining a vector of numeric values for nice
, one must consider that these values will be used to determine the extend the number is rounded up.
For example, if the number to round is 10.1, with the default nice
, this will round to 20. This is determined by taking the base-10 log of the input value
raising it to the power of 10 and then multiplying that value by each nice
value; the value selected is the lowest of which is bigger than the input. The
calculation would follow as such:
10^floor(log10(10.1)) = 1
10^1 = 10
10 * (1,2,4,5,6,8,10) = 10 20 40 50 60 80 100
So, 20 would be selected as it is the closest value in this range that is greater than 10.1. Adjust the nice
to suit the situation.
A numeric vector with all numbers rounded up nicely.
Adapted from Tommy's StackOverflow contribution: https://stackoverflow.com/questions/6461209/how-to-round-up-to-the-nearest-10-or-100-or-x
pretty
round_up_nice(x=c(1,4,5,10.1,55.5,60.2, 1001.3), nice = c(1,2,4,14))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.