Skip to content
Back to formatted view

Raw Message

Message-ID: <CABdHhvHXXT6cGz+JO=2rmWHSmFtbFqWmPvYyut_gfgTKZm_N8w@mail.gmail.com>
Date: 2011-11-04T00:33:53Z
From: Hadley Wickham
Subject: any updates w.r.t. lapply, sapply, apply retaining classes
In-Reply-To: <CAKfbWjtiSziUMh3sETk6JqDKz2GsrhugGkLcWs=AKSMN+r4_kA@mail.gmail.com>

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

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/