[R] effective way to return only the first argument of "which()"

Mike Spam ichmagspam at googlemail.com
Wed Sep 19 17:17:17 CEST 2012


Hi,

Thanks Michael, but i think this is even slower.

 x <-sample(20000000)
 which(x < 5)[1]
 which.max(x < 5)
 system.time(for(i in 1:100) which.max(x < 5))
       User      System verstrichen
      60.84       13.70       86.33
 system.time(for(i in 1:100) which(x < 5)[1])
       User      System verstrichen
      40.45        8.25       48.95



Thanks,
Nico




More information about the R-help mailing list