[R] generating a sequence --- need fast [lt]apply ()

Martin Maechler maechler at stat.math.ethz.ch
Tue Dec 21 17:14:39 CET 1999

>>>>> On Tue, 21 Dec 1999 15:23:49 +0000 (GMT), Prof Brian Ripley <ripley at stats.ox.ac.uk> said:

    BDR> OK, so we have now seen essentially three solutions:
    BDR> Me:

    BDR> A <- matrix(1, n-1, n-1)
    BDR> rA <- row(A)
    BDR> rA[rA + col(A) <= n]

    BDR> Jonathan Rougier:

    BDR> rA <- outer(1:n, 1:n, "-")
    BDR> rA[rA>=1]

    BDR> Andy Royle:

    BDR> sequence((n-1):1)

    BDR> Timings for n=500 on a 1994 Sun Sparc 20:

    BDR> 3.29, 4.68 and 23.86 seconds.

    BDR> I deliberately did not use outer, as it calls apply and 
    BDR> is normally quite slow.  row and col are internal operations and fast.

Thanks a lot.

I hope this reminds more people than just me
that we (R users) "desperately" need someone who

rewrites  apply(),lapply(), and tapply()  
to become much faster (as they are with S-plus [34].y, but not 5.[12])...

Anyone working on this ?

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