Can somebody give a hint on how to speed-up the following loop: for(j in 0:KM1) { k=j*60 for(i in 1:60) { dat$yvac[k+i]= rbinom(1,dat$nvac[k+i],dat$p.trt[j+i]) } } K1=999 -- -Tony [[alternative HTML version deleted]]
On Tue, 29 Sep 2009, Antonio Paredes wrote:> Can somebody give a hint on how to speed-up the following loop: > > > for(j in 0:KM1) > { > k=j*60 > for(i in 1:60) > { > dat$yvac[k+i]= rbinom(1,dat$nvac[k+i],dat$p.trt[j+i]) > } > } > > K1=999How about: rbinom((KM1 + 1)*60, dat$nvac, dat$p.trt[rep(0:KM1, each=60) + 1:60]) HTH Ray Brownrigg