[R] nested for loops

Romain Francois romain.francois at dbmail.com
Mon Jul 5 23:12:23 CEST 2010


Le 05/07/10 23:06, Senay ASMA a écrit :
>
> Dear Admin,
> I will appreciate if you advise me an effective way to write the following R
> code including nested for loops. I cannot do it by using expand.grid
> function because it results with memory allocation problems.
> Thanks for your time and consideration.
>
> for(d1 in 0:n){
> for(d2 in 0:n){
> for(d3 in 0:n){
> for(d4 in 0:n){
> for(d5 in 0:n){
> for(d6 in 0:n){
> for(d7 in 0:n){
> for(d8 in 0:n){
> for(d9 in 0:n){
> for(d10 in 0:n){
> for(d11 in 0:n){
> for(d12 in 0:n){
> for(d13 in 0:n){
> for(d14 in 0:n){
> for(d15 in 0:n){
> for(d16 in 0:n){
> for(d17 in 0:n){
> for(d18 in 0:n){
> for(d19 in 0:n){
> for(d20 in 0:n){
>
> list=c(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20)
> }}}}}}}}}}}}}}}}}}}}

Probably not what you want, but this should replicate the same effect as 
the code you posted:

list <- rep( n, 20 )

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5



More information about the R-help mailing list