Rfast (version 1.7.3)

Binary search algorithm: Binary search algorithm

Description

Binary search algorithm.

Usage

binary_search(x, v, index=FALSE)

Arguments

x
A vector with the data.
v
A value to check if exists in the vector x.
index
A boolean value for choose to return the position inside the vector.

Value

Search if the v exists in x. Then returns TRUE/FALSE if the value is been found.

Details

The functions is written in C++ in order to be as fast as possible.

See Also

is_element

Examples

Run this code
x <- rnorm(10000)
v <- x[500]
system.time( b <- binary_search(x,v) )
system.time( b1 <- binary_search(x,v,TRUE) )

Run the code above in your browser using DataLab