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 =

[R] speed issues? read R_inferno by Patrick Burns: a memory query

2010-12-23 Thread maddox
Hi, I'm just starting out with R and came across R_inferno.pdf by Patrick Burns just yesterday - I recommend it! His description of how 'growing' objects (e.g. obj - c(obj, additionalValue) eats up memory prompted me to rewrite a function (which made such calls ~210 times) so that it used

Re: [R] speed issues? read R_inferno by Patrick Burns: a memory query

2010-12-23 Thread Uwe Ligges
Actually the issue is not the size of memory that is consumed, but that memory allocation takes place and the object is copied in each iteration of the bad loop you have given below. This is not required for the second loop, where R can allocate the memory at once and does not need to copy the

Re: [R] speed

2010-03-10 Thread jim holtman
Hard to say. You might want to run a profile of each set of code and see where it is spending its time. It looks like from the R code that they are using vectorized operations and depending on how some of them are implemented, they might be calling C code to do most of the work. With the proper

Re: [R] speed

2010-03-10 Thread Matthew Dowle
Your choice of subject line alone shows some people that you missed some small details from the posting guide. The ability to notice small details may be important for you to demonstrate in future. Any answer in this thread is unlikely to be found by a topic search on subject lines alone

[R] speed

2010-03-09 Thread Adam Majewski
Hi, I have found some example of R code : http://commons.wikimedia.org/wiki/File:Mandelbrot_Creation_Animation_%28800x600%29.gif When I run this code on my computer it takes few seconds. I wanted to make similar program in Maxima CAS :

[R] Speed up sparse matrices

2010-03-08 Thread Feng Li
Dear R, I have three matrices like this K: pp-by-pp commutation matrix, I: p-by-p diagonal matrix, X: p-by-q dense matrix, and I wish to calculate K(IoX) where `o' denotes Kronecker product. Can you give me any suggestion to speed it up when `p' and `q' are large? Thanks in

[R] Speed of accessing list element by index or name

2009-12-03 Thread Peng Yu
I'm wondering if the speed of accessing list element by index is the same as that of accessing list element by name. l[[1]] l[['name']] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Speed of accessing list element by index or name

2009-12-03 Thread Sharpie
pengyu.ut wrote: I'm wondering if the speed of accessing list element by index is the same as that of accessing list element by name. l[[1]] l[['name']] Have you tried answering this question yourself using the system.time() function? -- View this message in context:

Re: [R] Speed of accessing list element by index or name

2009-12-03 Thread Jorge Ivan Velez
One way to answer it would be comparing: system.time(replicate(10^5, l[[1]] ) ) system.time(replicate(10^5, l[['name']] ) ) HTH, Jorge On Fri, Dec 4, 2009 at 1:01 AM, Peng Yu wrote: I'm wondering if the speed of accessing list element by index is the same as that of accessing list element

[R] Speed up R code

2009-11-23 Thread AnnaFowler
Hi, Im new to R and having some trouble with my code - it works, its just very slow! Ive tried lots of things, but nothing quite seems to work, so any help and suggestions would be really appreciated! I want to calculate the marginal likelihood for every element of a row of a matrix and the

Re: [R] Speed up R code

2009-11-23 Thread SL
Loops tend to dramatically increase computation time. You may re-write a vectorized version of your code if possible, i.e. use matrix algebra. Calculus is a lot faster if one can avoid loops (at least some of them) . Best, Stephane 2009/11/23 AnnaFowler a.fowle...@imperial.ac.uk: Hi, Im new to

Re: [R] Speed up R code

2009-11-23 Thread AnnaFowler
Thanks Stephane, Thats a great help! SL-16 wrote: Loops tend to dramatically increase computation time. You may re-write a vectorized version of your code if possible, i.e. use matrix algebra. Calculus is a lot faster if one can avoid loops (at least some of them) . Best, Stephane

Re: [R] Speed up and limit memory usage of lm()

2009-10-12 Thread Dieter Menne
gauti wrote: I have been doing series of linear regression models lm(). In this case the execution time and memory usage becomes a huge issue. I have therefore been trying to speed the process and limit the memory usage. Have a look at package biglm. Dieter -- View this message

<    1   2