Re: R-beta: get index numbers of vector?

Thomas Lumley (thomas@biostat.washington.edu)
Fri, 10 Apr 1998 09:01:14 -0700 (PDT)


Date: Fri, 10 Apr 1998 09:01:14 -0700 (PDT)
From: Thomas Lumley <thomas@biostat.washington.edu>
To: Bill Simpson <wsimpson@uwinnipeg.ca>
Subject: Re: R-beta: get index numbers of vector?
In-Reply-To: <Pine.OSF.3.95.980410102921.22823A-100000@io.uwinnipeg.ca>

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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._