0

I'm new to R so I'm still trying to figure things out.

I've got multiple raw datasets called with headers region and populationXXXX. The XXXX in the population header is the year.

All of the datasets have the exact same values in the region column, the only difference is the values in the population column which differ by year.

For example my first data set looks like this:

  Region          Population2000
1 Central Coast   85,000  
2 South Coast     3,000 

My second dataset looks like this:

  Region          Population2001
1 Central Coast   80,000  
2 South Coast     4,000

I have 8 of these datasets (spanning from 2000 to 2007, and I would like to join them all into one and to look like this (I've only included the first two years):

  Region          Population2000   Population2001
1 Central Coast   85,000           80,000
2 South Coast     3,000            4,000

Is there an efficient way to do this without using multiple full joins based on region?

Thanks!

Big Rick
  • 166
  • 9
  • Eventually you can cbind() your datasets, e.g. `cbind(BOD, BOD[-1])` – jogo Sep 08 '20 at 07:08
  • If your dataframes are called `df1`, `df2`, `df3` etc. You can do `Reduce(function(x, y) merge(x, y, by = 'Region'), mget(paste0('df', 1:8)))` – Ronak Shah Sep 08 '20 at 07:08

0 Answers0