Re: [R] finding the next highest number in an array

2010-07-28 Thread Bert Gunter
... just a note: you don't have to first sort the vector to do this: > x <- sample(1:7) > x [1] 3 5 7 6 2 4 1 > which(x==min(x[x>4])) [1] 2 Bert Gunter Genentech Nonclinical Biostatistics On Wed, Jul 28, 2010 at 3:12 AM, Raghu wrote: > Hi > > I have a sorted array ( in ascending order) and I

Re: [R] finding the next highest number in an array

2010-07-28 Thread David Winsemius
On Jul 28, 2010, at 7:28 AM, Dimitris Rizopoulos wrote: a couple of the many possible ways are: x <- c(23,36,45,62,79,103,109) thr <- 67 x[x > thr][1] head(x[x > thr], 1) Since he wanted the subscript rather than the number wouldn't it be: which(x > 67)[1] head( which(x > 67), 1) -- Davi

Re: [R] finding the next highest number in an array

2010-07-28 Thread Dimitris Rizopoulos
a couple of the many possible ways are: x <- c(23,36,45,62,79,103,109) thr <- 67 x[x > thr][1] head(x[x > thr], 1) I hope it helps. Best, Dimitris On 7/28/2010 12:12 PM, Raghu wrote: Hi I have a sorted array ( in ascending order) and I want to find the subscript of a number in the array w

[R] finding the next highest number in an array

2010-07-28 Thread Raghu
Hi I have a sorted array ( in ascending order) and I want to find the subscript of a number in the array which is the the next highest number to a given number. For example,if I have 67 as a given number and if I have a vector x=c(23,36,45,62,79,103,109), then how do I get the subscript 5 from x (