Hi,

In general, the way to speed up for loops in R is to avoid them.  It
looks like some of the operations could be vectorized (e.g., h[1,k] +
vv[j-1,k+1] looks like you could just add entire columns at once).  If
you provide sample data for all the variables in your loop, it will be
possible to give you more detailed feedback.

Cheers,

Josh

2010/10/30 20c <2...@email.it>:
> Hi all,
>
> how can i make the following loop faster?
>
> vv[20001,22]=v[20001,22]
> for(k in 21:1) {
>  for(j in 20001:2) {
>   vv[j-1,k+1]=min(xx[j-1]*v[j-1,k+1],vv[j,k+1])
>   v[j,k]=h[1,k]+vv[j-1,k+1]
>  }
> vv[20001,k]=v[20001,k]
> }
>
>
>
> Thanks
>
> Lorenzo
>
>
>
>
>
>  --
>
>  Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP 
> autenticato? GRATIS solo con Email.it http://www.email.it/f
>
>
>
>  Sponsor:
>
>  Idee Regalo Personalizzate a partire da euro 3.90! Su MisterCupido.com alta 
> qualitя a prezzi imbattibili... e questa settimana GRATIS per te, la 
> confezione regalo!
>
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11027&d=30-10
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

______________________________________________
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.

Reply via email to