[R] automatically generate the output name of my "for" loops

jim holtman jholtman at gmail.com
Mon Jun 13 19:31:58 CEST 2011


If you want to have multidimensioned list, here is one way of doing it
by making sure you initialize the second level before using it:

data2 <- matrix(1:30, nrow = 10)
data3 <- matrix(1:300, nrow = 100)
data1 <- list()  # init to a list
for (j in 1:10){
    data1[[j]] <- list()  #    create second level list
    for (i in 1:100){
        data1[[j]][[i]] <- rbind(data2[j, ], data3[i, ])
    }
}

notice the reversal of the indices.

On Mon, Jun 13, 2011 at 12:29 PM, jiliguala <jiliguala at mail.com> wrote:
> hi, really thank u, Petr Pikal
>
> problem solved already.
>
> but here is another question:
>
> for(i in 1:100)
> data1[[i]] <- rbind(data2[1,], data3[i,])
>
> the codes above are no problem,
> but now i wnna do two loops like the codes below which have problem(the bold
> letters):
> i dont know what should be put in the bold letters place.
>
> for (j in 1:10)
> for (i in 1:100)
> data1[[i]][[j]] <- rbind(data2[j,], data3[i,])
>
>
> thanks for helping.
>
> daniel
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/automatically-generate-the-output-name-of-my-for-loops-tp3592160p3594243.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list