How to convert a list of dataframes in to a single dataframe using R

+1 vote

I have a code which results as a list of data frames, which I want to convert to a single data frame.

Here's an example :

list_Of_Data_Frames <- vector(mode = "list", length = 100)
for (i in 1:100) {
    list_Of_Data_Frames[[i]] <- data.frame(a=sample(letters, 500, rep=T),
                             b=rnorm(500), c=rnorm(500))
}

I am currently using this:

  data <- do.call("rbind", list_Of_Data_Frames)
Apr 13, 2018 in Data Analytics by BHARANI
• 420 points
6,963 views

1 answer to this question.

+1 vote

You can use the plyr function:

data <- ldply(list_Of_Data_Frames, data.frame)

This is a little slower than the original:

system.time({ data <- do.call("rbind", list_Of_Data_Frames) })
   user  system elapsed 
   0.25    0.00    0.25  system.time({ data2 <- ldply(list_Of_Data_Frames, data.frame) })
   user  system elapsed 
   0.30    0.00    0.29 identical(data, data2)
[1] TRUE
answered Apr 14, 2018 by Sahiti
• 6,370 points
Is it possible to sort or order or group_by  an output data.frame by a column "a" values ? Some of them are reapeted and scattered i.e.:

p, j, d, etc.
You can order or sort data frame using arrange function in the dplyr package or using order or sort method.
Thanks, @Kiran. Can you please make this an answer? It'll be easier for other readers to understand and I can upvote your answer.. Thanks!
Thanks, @Laila. I'm glad it helped!!

I commented on the question because it is not the answer to the main question.

Related Questions In Data Analytics

0 votes
1 answer

How to limit output of a dataframe in R?

For randomly sampling a row/cell where a ...READ MORE

answered Apr 18, 2018 in Data Analytics by kappa3010
• 2,090 points
3,329 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,750 views
0 votes
2 answers

how to convert a data frame into a list in R

Convert whole data frame into a list?? ...READ MORE

answered Sep 4, 2019 in Data Analytics by anonymous
• 33,030 points
1,283 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,884 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,619 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,287 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,130 points

edited Apr 12, 2018 by nirvana 22,078 views
0 votes
1 answer
0 votes
1 answer

How to convert a sentence to word table in R?

Try the following code: sentence <- c("case sweden", ...READ MORE

answered Jun 21, 2018 in Data Analytics by Sahiti
• 6,370 points
1,474 views
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by Sahiti
• 6,370 points
3,806 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP