R/in_interval.R

Defines functions in.interval.lo nin.interval.lo in.interval.ro nin.interval.ro

Documented in in.interval.lo in.interval.ro nin.interval.lo nin.interval.ro

#' @title Checks if values are outside of an interval (open on the
#'   right)
#' @description This function checks if the values in the `x`
#'   parameter are contained in the interval [`lo`, `hi`).
#'   `NA` values are treated as "not in the interval".
#' @param x A vector of values. (Lists will be coerced to a numeric vector.)
#' @param lo Left end of the interval.
#' @param hi Right end of the interval.
#' @return A boolean vector of the same length as `x`.
#' @seealso [in.interval.lo()], [in.interval.ro()],
#'   [nin.interval.lo()]
#' @examples
#' nin.interval.ro(c(-1, 0, 1, 2), 0, 1)
#' nin.interval.ro(NA, 1, 3)
#' @export
nin.interval.ro <- function(x, lo, hi) is.na(.bincode(x, c(lo, hi), right = F))

#' @title Checks if values are contained in an interval (open on the
#'   right)
#' @description This function checks if the values in the `x`
#'   parameter are contained in the interval [`lo`, `hi`).
#'   `NA` values are treated as "not in the interval".
#' @param x A vector of values. (Lists will be coerced to a numeric
#'   vector.)
#' @param lo Left end of the interval.
#' @param hi Right end of the interval.
#' @return A boolean vector of the same length as `x`.
#' @seealso [in.interval.lo()], [nin.interval.lo()],
#'   [nin.interval.ro()]
#' @examples
#' in.interval.ro(c(-1, 0, 1, 2), 0, 1)
#' in.interval.ro(NA, 1, 3)
#' @export
in.interval.ro <- function(x, lo, hi) !nin.interval.ro(x, lo, hi)

#' @title Checks if values are outside of an interval (open on the left)
#' @description This function checks if the values in the `x`
#'   parameter are contained in the interval (`lo`, `hi`].
#'   `NA` values are treated as "not in the interval".
#' @param x A vector of values. (Lists will be coerced to a numeric
#'   vector.)
#' @param lo Left end of the interval.
#' @param hi Right end of the interval.
#' @return A boolean vector of the same length as `x`.
#' @seealso [in.interval.lo()], [in.interval.ro()],
#'   [nin.interval.ro()]
#' @examples
#' nin.interval.lo(c(-1, 0, 1, 2), 0, 1)
#' nin.interval.lo(NA, 1, 3)
#' @export
nin.interval.lo <- function(x, lo, hi) is.na(.bincode(x, c(lo, hi), right = T))

#' @title Checks if values are contained in an interval (open on the
#'   left)
#' @description This function checks if the values in the `x`
#'   parameter are contained in the interval (`lo`, `hi`].
#'   `NA` values are treated as "not in the interval".
#' @param x A vector of values. (Lists will be coerced to a numeric
#'   vector.)
#' @param lo Left end of the interval.
#' @param hi Right end of the interval.
#' @return A boolean vector of the same length as `x`.
#' @seealso [in.interval.ro()], [nin.interval.lo()],
#'   [nin.interval.ro()]
#' @examples
#' in.interval.lo(c(-1, 0, 1, 2), 0, 1)
#' in.interval.lo(NA, 1, 3)
#' @export
in.interval.lo <- function(x, lo, hi) !nin.interval.lo(x, lo, hi)

Try the kimisc package in your browser

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

kimisc documentation built on April 3, 2025, 6:39 p.m.