我有一个如下所示的数据帧列表:
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)
这里,单位A到D的值对应于一年.
从这个列表中,我想获得一个新列表,其中每个数据帧对应于相同单位a到D的每个单独年份的值.这些新数据帧应该如下所示:
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))
谢谢