Created
June 5, 2019 10:28
-
-
Save eddjberry/440568d253610b904d2388a1767b629d to your computer and use it in GitHub Desktop.
Round values to the nearest 0.05, 5, 10 etc.
This file contains 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 a value to the nearest digit | |
# e.g. if nearest = 5 then 42 would round to 40 | |
# and 47 would be rounded to 45 | |
# source: http://r.789695.n4.nabble.com/Rounding-to-the-nearest-5-td863189.html | |
round_nearest <- function(x, nearest) { | |
nearest * round(x / nearest) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment