[R] Vectorize multiple loops

Henrique Dallazuanna wwwhsd at gmail.com
Fri Jan 29 13:16:52 CET 2010


Try this:

 aperm(outer(i %o% k, j, FUN = "-"), c(1, 3, 2))

On Fri, Jan 29, 2010 at 9:58 AM, Kohleth Chia <kohleth at gmail.com> wrote:
> Hi,
>
> How can we vectorize multiple for loops?
>
> E.g. how do you vectorize this:
>
> for (i in 1:10){
>  for(j in 1:25){
>  for(k in 1:19){
>   x[i,j,k]=i*k-j
>  }
>  }
> }
>
> THanks
> ------------
> KC
>
> ______________________________________________
> R-help at 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list