[R] A point in a vector?
David Winsemius
dwinsemius at comcast.net
Wed Sep 30 22:48:21 CEST 2009
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 [4,6] that is in the subinterval
> starting from
> element j=7 to the element j+1=8.
sum(x > v)
> v[sum(x > v)]
[1] 4
> v[sum(x > v)+1]
[1] 6
>
> Can we do that with an R command?
>
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list