[R] A point in a vector?

2009-09-30 Thread Corrado
Dear list, I have a strange requirement I have a vector, for example v- c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x- 4.8. I would like to understand in which sub interval of v is x. In this case, v would be in the sub interval [4,6] that is in the subinterval starting from

Re: [R] A point in a vector?

2009-09-30 Thread Henrique Dallazuanna
Try this: v[findInterval(x, v) + 0:1] On Wed, Sep 30, 2009 at 5:10 PM, Corrado ct...@york.ac.uk wrote: Dear list, I have a strange requirement I have a vector, for example v- c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x- 4.8. I would like to understand in which sub

Re: [R] A point in a vector?

2009-09-30 Thread baptiste auguie
Hi, assuming v is sorted, try this, v[ findInterval(x,v)+0:1 ] see ?findInterval and perhaps ?cut HTH, baptiste 2009/9/30 Corrado ct...@york.ac.uk: Dear list, I have a strange requirement I have a vector, for example v- c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x-

Re: [R] A point in a vector?

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 4:10 PM, Corrado wrote: Dear list, I have a strange requirement I have a vector, for example v- c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x- 4.8. I would like to understand in which sub interval of v is x. In this case, v would be in the sub interval