R/Interval_round.R

Defines functions interval_round

Documented in interval_round

#' Interval round
#'
#' Function to round numeric values in a vector to values from
#' an interval sequence.
#'
#' @param x The numeric vector to adjust
#' @param interval The interval sequence
#' @examples
#' interval_round(c(5, 4, 2, 6), interval = seq(1:4))
#'
#' @family vector calculations
#' @return The vector corrected for the given interval
#' @export
interval_round <- function(x, interval) {
  x <- interval[ifelse(x < min(interval), 1, findInterval(x, interval))]
  return(x)
}

Try the vvconverter package in your browser

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

vvconverter documentation built on June 22, 2024, 10:53 a.m.