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
• 410 points
194 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 13, 2018 by darklord
• 6,170 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,020 points
64 views
0 votes
2 answers
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 in Data Analytics by anonymous
• 31,840 points
44 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
161 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
131 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
105 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,060 points

edited Apr 12, 2018 by nirvana 3,622 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 darklord
• 6,170 points
30 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 darklord
• 6,170 points
176 views