Re: [R] "firstthat"?

About this list Date view Thread view Subject view Author view

From: Thomas Lumley (tlumley@u.washington.edu)
Date: Wed 21 Feb 2001 - 06:52:28 EST


Message-ID: <Pine.A41.4.33.0102201250110.167086-100000@homer34.u.washington.edu>

On Tue, 20 Feb 2001, Duncan Murdoch wrote:

> I need a function that's probably already in R, but I can't find it.
>
> What I want is a "firstthat" function. This will look through a logical
> vector and return the index of the first TRUE. Typical use would be like
> this:
>
> 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.

        -thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:33 EST