R/roundto.R

#' Round* a number to the nearest given value.
#' (* can use floor or ceiling).
#'
#' \code{roundto(x, z = 1, drop=NULL)}
#'
#' @param x a vector of numeric values
#' @param z the number to which rounding will be done
#' @param FUN the function for rounding, either round, floor or ceiling
#'
#' @details Simple convenience function for rounding* a number to
#' the nearest given value. (* can use floor or ceiling).
#'
#' @examples
#' roundto(1:10, 5, round)
#'
#' roundto(1:10, 5, floor)

roundto = function(x, z = 1, FUN = round){
  FUN(x/z)*z
}
helophilus/ColsTools documentation built on May 30, 2019, 4:03 p.m.