round_up_nice: Round up to a 'nice' number.

round_up_niceR Documentation

Round up to a 'nice' number.

Description

round_up_nice will examine a vector of numbers and round each upwards to a 'nice' value.

Usage

round_up_nice(x, nice = seq(1, 10))

Arguments

x

A data object.

nice

A numeric vector defining base values that the user believes are 'nice'.

Details

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.

Value

A numeric vector with all numbers rounded up nicely.

Source

Adapted from Tommy's StackOverflow contribution: https://stackoverflow.com/questions/6461209/how-to-round-up-to-the-nearest-10-or-100-or-x

See Also

pretty

Examples

round_up_nice(x=c(1,4,5,10.1,55.5,60.2, 1001.3), nice = c(1,2,4,14))


al-obrien/farrago documentation built on April 14, 2023, 6:20 p.m.