我有一个具有以下结构的列表:
$ List (length 13) ; 13 Types
$ --- Lists (Length 4) ; Each have 4 subsets of the same original data
$ ------- Dataframes 1, 2, 3, and 4 ; for each of 13 types
我想要
$ List (length 52) ; 52 Versions (Type_Subset)
$ --- Dataframes 1, 2, 3, ... 52 ; As separate elements in list
如何使用下面的mtcars
示例来做到这一点?
df <- list(Blue = list(mtcars[1:3,], mtcars[4:6,], mtcars[7:9,]),
Red = list(mtcars[10:12,], mtcars[13:15,], mtcars[16:18,]),
Green = list(mtcars[18:20,], mtcars[21:23,], mtcars[24:26,]))
# Need function on df ...
# new_df <- SingleNestLevel(df)
# Which yields:
list(Blue1 = mtcars[1:3,],
Blue2 = mtcars[4:6,],
Blue3 = mtcars[7:9,],
Red1 = mtcars[10:12,],
Red2 = mtcars[13:15,],
Red3 = mtcars[16:18,],
Green1 = mtcars[18:20,],
Green2 = mtcars[21:23,],
Green3 = mtcars[24:26,])
注意:我研究了类似this one之类的问题,但我想转换为一个嵌套级别,而不是完全扁平化我的结构。