R/floor_to.R

Defines functions floor_to

Documented in floor_to

#' @title floor_to: Rounds a number down
#' @description
#' Takes a numeric value or vector (x) and rounds it
#' down to the nearest multiple of a specified base (to).
#' If the to argument is not provided, it defaults to rounding down to the nearest integer.
#' The result is returned as a numeric value or vector of the same length as the input.
#' @param x numeric value or vector that you want to round down or floor.
#' @param to the base to which you want to round down the input value(s).
#' The default value is set to 1, meaning the function will round down to the nearest integer.
#' 
#' @return The number rounded down to the specified multiple.
#' 
#' @examples
#' floor_to(7, 3); # Returns 6, as 6 is the largest multiple of 3 less than or equal to 7.
#' floor_to(5, 2); # Returns 4, as 4 is the largest multiple of 2 less than or equal to 5.
#' 
#' @keywords arith
#' @export
floor_to <- function(x, to=1) {
  floored <- floor(x / to) * to;
  return(floored);
}#floor_to

Try the flexOR package in your browser

Any scripts or data that you put into this service are public.

flexOR documentation built on June 24, 2024, 5:26 p.m.