[R] "firstthat"?

Thomas Lumley tlumley at u.washington.edu
Tue Feb 20 21:52:28 CET 2001


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



More information about the R-help mailing list