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

2009-12-02 Thread jim holtman
Is this what you want: > x <- c(0,3,4) > ?findInterval > findInterval(2, x) [1] 1 > On Wed, Dec 2, 2009 at 9:34 AM, Hao Cen wrote: > 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 retur

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

2009-12-02 Thread David Winsemius
On Dec 2, 2009, at 9:34 AM, Hao Cen wrote: 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

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

2009-12-02 Thread Hao Cen
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(