I have a list of dataframes that look like this:
df_type1 <- data.frame(unit_name=c("A", "B", "C", "D"),
year_2014=c(653, 49, 563, 239),
year_2015=c(29, 63, 4879, 34),
year_2016=c(349, 340, 1, 47))
df_type2 <- data.frame(unit_name=c("A", "B", "C", "D"),
year_2014=c(573, 59, 563, 2999),
year_2015=c(39, 6390, 479, 98),
year_2016=c(5649, 640, 890, 12))
list_types <- list(df_type1, df_type2)
Here, values of units A to D correspond to a year.
From this list, I want to obtain a new list where each dataframe corresponds to the values of each separate year for the same units A to D. These new dataframes should look like this:
df_2014 <- data.frame(unit_name=c("A", "B", "C", "D"),
type1=c(653, 49, 563, 239), # these are the values of the column year_2014 in df_type1
type2=c(573, 59, 563, 2999))
df_2015 <- data.frame(unit_name=c("A", "B", "C", "D"),
type1=c(29, 63, 4879, 34),
type2=c(39, 6390, 479, 98))
df_2016 <- data.frame(unit_name=c("A", "B", "C", "D"),
type1=c(349, 340, 1, 47),
type2=c(5649, 640, 890, 12))