Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recombining a list of Data.frames into a single data frame [duplicate]

Tags:

list

dataframe

r

I am sorry if this question has been answered already. Also, this is my first time on stackoverflow.

I have a beginner R question concerning lists , data frames and merge() and/or rbind().

I started with a Panel that looks like this

COUNTRY YEAR VAR A         1 A         2 B         1 B         2 

For efficiency purposes, I created a list that consists of one data frame for each country and performed a variety of calculations on each individual data.frame. However, I cannot seem to combine the individual data frames into one large frame again.

rbind() and merge() both tell me that only replacement of elements is allowed.

Could someone tell me what I am doing wrong/ and how to actually recombine the data frames?

Thank you

like image 541
CGN Avatar asked Mar 06 '10 15:03

CGN


People also ask

How do you combine the data frames into a single data frame?

Key PointsPandas' merge and concat can be used to combine subsets of a DataFrame, or even data from different files. join function combines DataFrames based on index or column. Joining two DataFrames can be done in multiple ways (left, right, and inner) depending on what data must be in the final DataFrame.

How do I combine a list of DataFrames in R?

To combine data frames stored in a list in R, we can use full_join function of dplyr package inside Reduce function.

Can you have a list of data frames?

Creating a list of Dataframes. To create a list of Dataframes we use the list() function in R and then pass each of the data frame you have created as arguments to the function.

How do I combine two data frames with different number of rows?

Use the full_join Function to Merge Two R Data Frames With Different Number of Rows. full_join is part of the dplyr package, and it can be used to merge two data frames with a different number of rows.


1 Answers

Maybe you want to do something like:

do.call("rbind", my.df.list)

like image 161
datanalytics.com Avatar answered Oct 07 '22 16:10

datanalytics.com