Re: [R] beginner's loop issue

2012-03-14 Thread aledanda
Thank you all for your helpful comments! I solved my problem by creating an empty matrix before the loop and adjusting the loop itself, this is the code: size - dim(input) out - matrix('',nrow =size[1], ncol = 9) for (i in 1:nrow(input)) { out[i,1:3] -

[R] beginner's loop issue

2012-03-13 Thread aledanda
Dear All, I hope you don't mind helping me with this small issue. I haven't been using R in years and I'm trying to fill in a matrix with the output of a function (I'm probably using the Matlab logic here and it's not working). Here is my code: for (i in 1:length(input)){ out[i,1:3] -

Re: [R] beginner's loop issue

2012-03-13 Thread R. Michael Weylandt
Yes, the short answer is that you need to define out before running the loop. The most effective way to do so will be to set up a matrix with the exact right dimensions (if you know them up front); something like out - matrix(NA, nrow = length(input), ncol = 9) Michael On Tue, Mar 13, 2012 at

Re: [R] beginner's loop issue

2012-03-13 Thread Paul Johnson
On Tue, Mar 13, 2012 at 11:27 AM, aledanda danda.ga...@gmail.com wrote: Dear All, I hope you don't mind helping me with this small issue. I haven't been using R in years and I'm trying to fill in a matrix with the output of a function (I'm probably using the Matlab logic here and it's not