# R/in_interval.R In kimisc: Kirill's Miscellaneous Functions

```#' @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`.
#' @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`.
#' @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`.
#' @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`.