On Fri, 10 Apr 1998, Bill Simpson wrote:
> I have ordered x,y data. Suppose I have
> y<-c(1,2,3,4,5,6,5,4,3,2,1)
> x<-c(.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1)
>
> I want a function left(y,3) which returns the index of the first y value
> >3.
left<-function(xs,x){
n<-length(xs)
min( (1:n)[xs>x])
}
right<-function(xs,x){
n<-length(xs)
n+1-left(xs[n:1],x)
}
These return NA if no such value exists.
Thomas Lumley
------------------------------------------------------+------
Biostatistics : "Never attribute to malice what :
Uni of Washington : can be adequately explained by :
Box 357232 : incompetence" - Hanlon's Razor :
Seattle WA 98195-7232 : :
------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._