Re: [R] vectorising ifelse()

2005-07-22 Thread Adaikalavan Ramasamy
Does either 'zippo' or 'zappo' contain the values 1 or 2 ? If so, then you cannot vectorize this code because you are changing the values in 'new' at every iteration and potentially sampling a value from new[ ,1] or new[ ,2] . If not, then it might be possible to vectorize. Something along the

Re: [R] vectorising ifelse()

2005-07-22 Thread Federico Calboli
On 22 Jul 2005, at 11:20, Adaikalavan Ramasamy wrote: Does either 'zippo' or 'zappo' contain the values 1 or 2 ? If so, then you cannot vectorize this code because you are changing the values in 'new' at every iteration and potentially sampling a value from new[ ,1] or new[ ,2] .

[R] vectorising ifelse()

2005-07-21 Thread Federico Calboli
Hi All, is there any chance of vectorising the two ifelse() statements in the following code: for(i in gp){ new[i,1] = ifelse(srow[i]0, new[srow[i],zippo[i]], sample(1:100, 1, prob =Y1, rep = T)) new[i,2] = ifelse(drow[i]0, new[drow[i]0,zappo[i]], sample(1:100, 1, prob =Y1, rep = T)) }