我有一个数据框列表,看起来像这样:
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))