[R] any updates w.r.t. lapply, sapply, apply retaining classes

Hadley Wickham hadley at rice.edu
Fri Nov 4 01:33:53 CET 2011

>    In the example I give above, the impact might seem small, but the
> implications are *huge*.  This means that I am, in effect, not allowed to
> use *any* of the vectoring functions in 'R', which avoid performing loops
> thereby speeding up process time extraordinarily.  Many can sympathize that
> 'R' is ridiculously slow with "for" loops, compared to other languages.
>  But that's theoretically OK, a good statistician or data analyst should be
> able to work comfortably with matrices and vectors.

Two comments:

* sapply is generally only _slightly_ faster than a for loop

* it's almost always better to use vapply instead of sapply.

But I agree that simplify2array should be a generic so that you can
write custom methods to support new classes.


Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University

More information about the R-help mailing list