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

0 votes

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
• 400 points
124 views

1 answer to this question.

0 votes

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,140 points

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
46 views
0 votes
2 answers
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,700 points
97 views
0 votes
1 answer

How to join a list of data frames using map()

You can use reduce set.seed(24) r1 <- map(c(5, 10, ...READ MORE

answered Apr 11, 2018 in Data Analytics by kappa3010
• 2,020 points
42 views
0 votes
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,700 points
60 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,700 points
57 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 2,227 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,140 points
21 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,140 points
87 views