Assess if x
is between left
and right
bounds.
Shortcut for x >= left & x <= right
if strict=FALSE
(default).
Shortcut for x > left & x < right
if strict=TRUE
.
Arguments
- x
Numeric values to assess
- left
Numeric value(s) used as lower bound
- right
Numeric value(s) used as upper bound
- strict
Logical value defining if
x
is strictly betweenleft
andright
. Default value isFALSE
.
Examples
isBetween(1:12, 7, 9)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE
x <- rnorm(1e2)
x[isBetween(x, -1, 1)]
#> [1] 0.65537578 0.60827687 -0.74008826 -0.46146981 0.49445014 0.94440465
#> [7] 0.23260078 -0.52826888 0.68350078 0.95025771 -0.82019471 0.75844686
#> [13] -0.26344347 0.36643423 -0.65536554 0.92345884 0.49065356 -0.13986062
#> [19] -0.45251848 0.12813283 0.37285821 -0.57154628 -0.75559839 -0.34528012
#> [25] 0.57937149 0.15626534 0.25620473 -0.27152918 0.20395297 0.68979203
#> [31] 0.24893329 -0.70983120 0.47982484 -0.91466627 -0.40658492 -0.07800199
#> [37] 0.17956754 0.29804904 -0.11739930 -0.69867395 -0.52455120 -0.23873432
#> [43] 0.66580256 0.81503942 -0.56219722 -0.44268198 0.02254404 -0.25265453
#> [49] 0.01463881 0.17189805 0.04045542 0.02911272 0.32461708 -0.59233324
#> [55] 0.20171169 -0.66836737 -0.39036436 0.78777681 -0.81089843 -0.87946233
#> [61] 0.19553659 -0.43808444 0.31934689 0.36322168 0.13390582 0.95355227
#> [67] 0.24844373 0.36030857 -0.51707619 -0.06081439
isBetween(x, cos(x) + 1, cos(x) - 1)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [97] FALSE FALSE FALSE FALSE