0

I have several dataframes that have two columns, Year (which is present on all dataframes and have the same values) and each dataframe has a unique column with different data and column name. I have 8 dataframes so I would like my new combined dataframe to have 9 columns, being the first one the column Year.

I've tried using rbind to combine the dataframes but I got an error saying:

rbind(df_GazaSampleSize, MeanSchoolingGaza, MeanAgeGaza, MeanLabourGaza, MeanWageEarnerGaza, MeanDaysWorkedGaza, MeanMarriedGaza, WorkInIsraelForGaza)

Error in match.names(clabs, names(xi)) : 
  names do not match previous names
 

All of my dataframes have exactly two columns and 11 rows (without taking into consideration the column name). This is an example of one dataframe named MeanAgeGaza:

   year      age
1    81 33.04291
2    82 32.62763
3    83 32.65788
4    84 32.86730
5    85 32.67479
6    86 32.38068
7    87 32.72235
8    88 32.93970
9    89 33.27995
10   90 33.20490
11   91 33.24092

I would like for the columns to be arranged like:

Year, df_GazaSampleSize, MeanSchoolingGaza, MeanAgeGaza, MeanLabourGaza, MeanWageEarnerGaza, MeanDaysWorkedGaza, MeanMarriedGaza, WorkInIsraelForGaza that's why I tried doing the rbind.

Is there any way to do this ? Any help is appreciated

F M
  • 1
  • 1
  • 1
    The base R merge() function would be appropriate. rbind() is for concatenating (think of it as stacking on top of each other) dataframes that have the same columns. – Bill O'Brien Jul 09 '21 at 15:11
  • Perhaps this is useful for you: https://stackoverflow.com/a/34393416/11832955 – ludvigolsen Jul 09 '21 at 21:55

0 Answers0