Re: [R] for loop vectorization

2009-05-07 Thread miraceti
this 'ifelse' usage looks promising. thank you very much. On Thu, May 7, 2009 at 3:12 PM, Patrick Burns wrote: > If you haven't seen it yet, > 'The R Inferno' may be of use > to you. > > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of "The R I

Re: [R] for loop vectorization

2009-05-07 Thread miraceti
uhoh, missed two lines on the top.Sorry about that. the whole code looks like this. nchars = 4 maxvals = c(2,2,2,2) tmp = 0:(maxvals[1]) for(i in 2:nchars) { tmp <- outer(tmp, 0:(maxvals[i]), FUN="paste", sep=".") } states = tmp stateidx = array(1:length(states), dim=dim(states)) transition <-

[R] for loop vectorization

2009-05-07 Thread miraceti
Hi, I am still not familiar with vectorization. Could you help with making this for loop more efficient? The code is trying to make a Q matrix for a multidimensional state space with specific conditions. thanks Mira tmp = 0:(maxvals[1]) for(i in 2:nchars) { tmp <- outer(tmp, 0:(maxvals[i]), FU