#' Round numbers by a specyfic value
#'
#' @param x numeric vector.
#' @param by rounding value.
#' @param roundUp if \code{TRUE} then categories are rounded up.
#' @param symmetric if \code{TRUE} then categories are symmetric around zero
#' (rather than rounded up or down).
#' @examples
#'
#' x <- seq(-5, 5, by = 0.5)
#' rbind(roundBy(x, roundUp = F, symmetric = F),
#' roundBy(x, roundUp = T, symmetric = F),
#' roundBy(x, roundUp = F, symmetric = T),
#' roundBy(x, roundUp = T, symmetric = T))
#'
#' @export
roundBy <- function(x, by = 1, roundUp = FALSE, symmetric = FALSE) {
sgn <- if (symmetric) sign(x) else 1
if (roundUp) ceiling(x*sgn/by)*by*sgn
else floor(x*sgn/by)*by*sgn
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.