0

i get some list data(as follow) and want to change them into dataframe/matrix in R

length(df[[1]][[1]])
# [1] 11

length(df[[1]])
# [1] 20

length(df)
# [1] 423

and i want to change them into a dataframe/matrix with structure ncol = 11, nrow=8460(423*20),how to do that with R? Thx!

Henrik
  • 65,555
  • 14
  • 143
  • 159
poemcao
  • 1
  • 1
  • 1
  • 4
    This is your first time posting. The code can not be run by others. Please provide data. Also spend some time formatting your question. When you don't take the time to capitalize/punctuate it leads others to believe this isn't that important. – Tyler Rinker Mar 05 '14 at 07:28
  • 5
    It is much easier to help if you provide a **minimal, self contained example**. Please check these links for general ideas, and how to do it in R: [**here**](http://stackoverflow.com/help/mcve), [**here**](http://www.sscce.org/), and [**here**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). Also have a look at a nice [**checklist for questions on SO**](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist). – Henrik Mar 05 '14 at 07:29

1 Answers1

2

like this with unlist(). I've created the list with random numbers:

df<-lapply(1:423,function(x){
  lapply(1:20,function(x)runif(11))
})

matrix(unlist(df),ncol=11,byrow=T)  # or byrow=F if you want to fill by col
Troy
  • 8,581
  • 29
  • 32