Last active
January 15, 2021 12:46
-
-
Save simonthompson99/acdf1248f1e13e19da6c6836b7a04303 to your computer and use it in GitHub Desktop.
[Pretty Round Up/Down] Round a number up or down to a pretty, convenient number #r
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-- function to round up or down a number nicely | |
roundNicely <- function(x, nice=c(1,1.5,2,2.5,3,4,5,6,8,10), down = TRUE) { | |
stopifnot(length(x) == 1) | |
if(down){ | |
10^floor(log10(x)) * nice[which(x <= 10^floor(log10(x)) * nice)[1] - 1] | |
} else { | |
10^floor(log10(x)) * nice[which(x <= 10^floor(log10(x)) * nice)[1]] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment