[R] "firstthat"?

Peter Dalgaard BSA p.dalgaard at pubhealth.ku.dk
Wed Feb 21 00:08:09 CET 2001


Thomas Lumley <tlumley at u.washington.edu> writes:

> On Tue, 20 Feb 2001, Duncan Murdoch wrote:

> > x _ runif(100)
> > x[firstthat(x > 0.8)]
> >
> 
> firstthat<-function(x) min(which(x))
> 
> does roughly what you want. It returns integer infinity if
> there are no matches.

Um. The result of which() is sorted, so how about

firstthat<-function(x) which(x)[1]

(gives NA if no matches)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list