Re: [R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-30 Thread Uwe Ligges
On 26.05.2010 08:52, Alan Lue wrote: Come to think of it, we can't save the output of each invocation and concatenate it later, since we need the output as input for the next iteration. Yes, but you can do it a bit cleverer than before by initializing to the fill length as in: r.seq -

Re: [R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-30 Thread Alan Lue
Is there a performance advantage to doing this, as opposed to growing the vector within the loop? I suppose R could have to dynamically reallocate memory at some point? Alan 2010/5/30 Uwe Ligges lig...@statistik.tu-dortmund.de: On 26.05.2010 08:52, Alan Lue wrote: Come to think of it, we

Re: [R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-30 Thread Uwe Ligges
On 30.05.2010 19:23, Alan Lue wrote: Is there a performance advantage to doing this, as opposed to growing the vector within the loop? I suppose R could have to dynamically reallocate memory at some point? Right, but that takes time since memory management is always expensive (and this way

[R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-26 Thread Alan Lue
Since `for' loops are slow in R, and since `apply' functions are faster, I was wondering whether there were a way to use an apply function—or to otherwise avoid using a loop—when iterating over a statement that updates its input. For example, here's some such code: r.seq - 2 * (1 / d$Dt[1] - 1)

Re: [R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-26 Thread Alan Lue
Come to think of it, we can't save the output of each invocation and concatenate it later, since we need the output as input for the next iteration. Alan On Tue, May 25, 2010 at 11:43 PM, Alan Lue alan@gmail.com wrote: Since `for' loops are slow in R, and since `apply' functions are

Re: [R] Avoiding Loops When Iterating Over Statement That Updates Its Input

2010-05-26 Thread Dennis Murphy
Hi: On Tue, May 25, 2010 at 11:43 PM, Alan Lue alan@gmail.com wrote: Since `for' loops are slow in R, and since `apply' functions are faster, I was wondering whether there were a way to use an apply function—or to otherwise avoid using a loop—when iterating over a statement that updates