[R] find the index of the next largest element in a sorted vector

Hao Cen hcen at andrew.cmu.edu
Wed Dec 2 15:34:45 CET 2009


Hi,

How can I find the index of the next largest element in a sorted vector if
an element is not found.

for example, searching 2 in c(0,3,4) would return 1 since 2 is not in the
vector and 0 is the next largest element to 2.

I tried which and match and neither returns such information.

> which(c(0,3,4) == 2)
integer(0)
> match(2, c(0,3,4))
[1] NA


thanks

Jeff




More information about the R-help mailing list