Get the position of x in vector y
binary_search_r(x, y, tol = sqrt(.Machine$double.eps))
x | A numeric value |
---|---|
y | A numeric vector |
tol | double equal tolerance |
A integer of the x
position in y
.
binary_search_r(2.5, 1:10)#> [1] 3binary_search_r(1.2, 1:10)#> [1] 2binary_search_r(0.5, 1:10)#> [1] 1binary_search_r(9.5, 1:10)#> [1] 10binary_search_r(11, 1:10)#> [1] 11