The binary operator %btw% returns a logical vector indicating all values in a vector that fall within a specified lower and upper limit.

x %btw% y

Arguments

x

A numeric vector.

y

Either a numeric vector specifying a lower and upper limit, or a character string in the form '(x,y)', '[x,y]', '(x,y]', or '[x,y)'. Here x and y denote the lower and upper limits, while square brackets indicate the end point is included, while round parentheses indicate the end point is excluded.

Value

A logical vector.

Examples

x <- 1:10

# Limits specified as numeric vector
x[ x %btw% c( 3, 6 ) ]
#> [1] 4 5 6

# Limits specified as character string
x[ x %btw% '(3,6)' ]
#> [1] 4 5
x[ x %btw% '[3,6]' ]
#> [1] 3 4 5 6
x[ x %btw% '(3,6]' ]
#> [1] 4 5 6
x[ x %btw% '[3,6)' ]
#> [1] 3 4 5