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=999

How about:

rbinom((KM1 + 1)*60, dat$nvac, dat$p.trt[rep(0:KM1, each=60) + 1:60])

HTH
Ray Brownrigg

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
  • [R] for loop Antonio Paredes
    • Re: [R] for loop Ray Brownrigg

Reply via email to