View source: R/binary_search.R
Binary search algorithm | R Documentation |
Search a value in an ordered vector.
binary_search(x, v, index=FALSE)
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. |
The functions is written in C++ in order to be as fast as possible.
Search if the v exists in x. Then returns TRUE/FALSE if the value is been found.
Manos Papadakis
R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.
is_element
x <- sort(rnorm(1000))
v <- x[50]
b <- binary_search(x,v)
b1 <- binary_search(x,v,TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.