Binary search implemented in R. Unoptimized