Re: [R] apply is slower than for loop?

2010-07-12 Thread Liviu Andronic
On Fri, Jul 9, 2010 at 9:11 PM, Gene Leynes gleyne...@gmail.com wrote: I thought the apply functions are faster than for loops, but my most recent test shows that apply actually takes a significantly longer than a for loop.  Am I missing something? Check Rnews for an article discussing proper

Re: [R] apply is slower than for loop?

2010-07-12 Thread Allan Engelhardt
On 12/07/10 08:16, Liviu Andronic wrote: On Fri, Jul 9, 2010 at 9:11 PM, Gene Leynesgleyne...@gmail.com wrote: [...] Check Rnews for an article discussing proper usage of apply and for. Liviu I am guessing you are referencing @article{Rnews:Ligges+Fox:2008

Re: [R] apply is slower than for loop?

2010-07-10 Thread Allan Engelhardt
On 09/07/10 21:19, Duncan Murdoch wrote: On 09/07/2010 4:11 PM, Gene Leynes wrote: I thought the apply functions are faster than for loops, but my most recent test shows that apply actually takes a significantly longer than a for loop. Am I missing something? Probably not. apply() needs

Re: [R] apply is slower than for loop?

2010-07-10 Thread Gene Leynes
Yes, that's actually quite helpful. I think this gets to the point that Patrick Burns was making in Ch. 4 of the Inferno book. I think the sapply is breaking the problem into chunks that make it more efficient. This is a prototype of a function that I will probably use quite often, so it's

[R] apply is slower than for loop?

2010-07-09 Thread Gene Leynes
I thought the apply functions are faster than for loops, but my most recent test shows that apply actually takes a significantly longer than a for loop. Am I missing something? It doesn't matter much if I do column wise calculations rather than row wise ## Example of how apply is SLOWER than

Re: [R] apply is slower than for loop?

2010-07-09 Thread Duncan Murdoch
On 09/07/2010 4:11 PM, Gene Leynes wrote: I thought the apply functions are faster than for loops, but my most recent test shows that apply actually takes a significantly longer than a for loop. Am I missing something? Probably not. apply() needs to figure out the shape of the results it

Re: [R] apply is slower than for loop?

2010-07-09 Thread Gene Leynes
I should add that I'm using R 2.10.1 on a Windows 7 machine, thanks! On Fri, Jul 9, 2010 at 3:11 PM, Gene Leynes gleyne...@gmail.comgleynes%...@gmail.com wrote: I thought the apply functions are faster than for loops, but my most recent test shows that apply actually takes a significantly