Explore Courses Blog Tutorials Interview Questions
+1 vote
in R Programming by (4k points)
edited by

Can someone please tell me a quick way to convert a nested list of data whose length is 100 and each item is a list of length 10 into a dataframe of 100 rows and 10 columns?

I am attaching a sample data:

5 <- replicate(


  list(sample(letters, 20)),

  simplify = FALSE


1 Answer

0 votes
by (46k points)
edited by

This is a quick way to perform your task:

df <- data.frame(matrix(unlist(5), nrow=length(5), byrow=T))

This will convert all character columns to factors, just add a parameter to the data.frame() call to avoid this:

df <- data.frame(matrix(unlist(5), nrow=100 , byrow=T),stringsAsFactors=FALSE)

Alternatively you can also use rbind, your_list)

There are other methods too but I think these two mentioned above will solve your problem.

Related questions

+4 votes
2 answers
asked May 29, 2019 in R Programming by Krishna (2.6k points)
+3 votes
1 answer
asked May 29, 2019 in R Programming by Anvi (10.2k points)

Browse Categories