Skip to content

Instantly share code, notes, and snippets.

@eddjberry
Created June 5, 2019 10:28
Show Gist options
  • Save eddjberry/440568d253610b904d2388a1767b629d to your computer and use it in GitHub Desktop.
Save eddjberry/440568d253610b904d2388a1767b629d to your computer and use it in GitHub Desktop.
Round values to the nearest 0.05, 5, 10 etc.
# 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