powered by
Finds the max index in a vector that does not exceed a target number.
find_max_ind(vals, target, start = 1)
The max index i such that vals[i] <= target and i >= start.
i
vals[i] <= target
i >= start
A vector of numbers.
A number. Must not be smaller than vals[start].
vals[start]
A number, the starting index; default to 1. Must be such that vals[start] <= target.
vals[start] <= target
for (i in 1:100) { vals <- 1:i for (start in 1:i) for (target in seq(start, i+0.5, by=0.5)) if (find_max_ind(vals, target, start) != floor(target)) stop() }
Run the code above in your browser using DataLab