Re: [R] speed up in R apply

2011-01-06 Thread Young Cho
When introduced to R, I learned how to use *apply whenever I could to avoid for-loops and all. And, getting the habit, I think I somehow got the mis-conception that it is a magic source, always an optimal way of coding in R. Thanks a lot for all of your helpful advice and comment! Young On Wed,

Re: [R] speed up in R apply

2011-01-06 Thread Liviu Andronic
On Wed, Jan 5, 2011 at 10:49 PM, Young Cho young.s...@gmail.com wrote: When introduced to R, I learned how to use *apply whenever I could to avoid for-loops and all. And, getting the habit, I think I somehow got the mis-conception that it is a magic source, always an optimal way of coding in

Re: [R] speed up in R apply

2011-01-06 Thread Uwe Ligges
On 05.01.2011 22:49, Young Cho wrote: When introduced to R, I learned how to use *apply whenever I could to avoid for-loops and all. And, getting the habit, I think I somehow got the mis-conception that it is a magic source, always an optimal way of coding in R. That is right, but your apply

[R] speed up in R apply

2011-01-05 Thread Young Cho
Hi, I am doing some simulations and found a bottle neck in my R script. I made an example: a = matrix(rnorm(500),100,5) tt = Sys.time(); sum(a[,1]*a[,2]*a[,3]*a[,4]*a[,5]); Sys.time() - tt [1] -1291.026 Time difference of 0.2354031 secs tt = Sys.time(); sum(apply(a,1,prod));

Re: [R] speed up in R apply

2011-01-05 Thread David Winsemius
On Jan 5, 2011, at 10:03 AM, Young Cho wrote: Hi, I am doing some simulations and found a bottle neck in my R script. I made an example: a = matrix(rnorm(500),100,5) tt = Sys.time(); sum(a[,1]*a[,2]*a[,3]*a[,4]*a[,5]); Sys.time() - tt [1] -1291.026 Time difference of 0.2354031

Re: [R] speed up in R apply

2011-01-05 Thread Douglas Bates
On Wed, Jan 5, 2011 at 1:22 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 5, 2011, at 10:03 AM, Young Cho wrote: Hi, I am doing some simulations and found a bottle neck in my R script. I made an example: a = matrix(rnorm(500),100,5) tt  = Sys.time();

Re: [R] speed up in R apply

2011-01-05 Thread David Winsemius
On Jan 5, 2011, at 2:40 PM, Douglas Bates wrote: On Wed, Jan 5, 2011 at 1:22 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 5, 2011, at 10:03 AM, Young Cho wrote: Hi, I am doing some simulations and found a bottle neck in my R script. I made an example: a =