[R] apply question

Giovanni Azua bravegag at gmail.com
Fri Apr 30 23:11:54 CEST 2010


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 and sapply?

Then the only advantage of these above is only syntactic sugar? 

>> 
>> 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,
Giovanni


More information about the R-help mailing list