in_interval: Determine if Value Lies within Interval

Description Usage Arguments Examples

View source: R/in_interval.R

Description

This function determines whether elements of a numeric vector x lie within boundaries [lo, hi). Marginally slower than the R equivalent code x >= lo & x < hi for small vectors; much faster for very large vectors.

Usage

1
in_interval(x, lo, hi, include.lower = TRUE, include.upper = FALSE)

Arguments

x

numeric. vector of numbers.

lo

numeric, length 1. lower boundary.

hi

numeric, length 1. upper boundary.

include.lower

boolean. include the lower endpoint?

include.upper

boolean. include the upper endpoint?

Examples

1
2
3
4
5
x <- runif(100); lo <- 0.5; hi <- 1
f <- function(x, lo, hi) {
  return( x >= lo & x < hi )
}
stopifnot( all( in_interval( x, lo, hi ) == f(x, lo, hi) ) )

Kmisc documentation built on May 29, 2017, 1:43 p.m.

Related to in_interval in Kmisc...