[R] apply question
petr.pikal at precheza.cz
Mon May 3 10:48:53 CEST 2010
r-help-bounces at r-project.org napsal dne 30.04.2010 23:11:54:
> Hello David,
> On Apr 30, 2010, at 11:00 PM, David Winsemius wrote:
> > Note: Loops may be just as fast or faster than apply calls.
> How come!? is this true also for other similar functions: lapply, tapply
> Then the only advantage of these above is only syntactic sugar?
Yes and no. If your loop(s) is poorly written it can be much slower then
*apply operator but usually not from loop point of view but from the code
> >> indices <- replicate(B,sample(1:N, size=N, replace=TRUE))
> >> theta_star <- apply(indices,2,statistic,data)
> > Why not:
> > theta_star <- apply(indices,2, function(x) statistic(data, x) )
> > May end up as a data class that needs further work, depending on what
> "statistic" return.
> Nice! thank you!
> Best regards,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help