我有两个维度的嵌套列表。每个元素都是data.frame。我想将其展平到一个维度
让我们举个例子。 order by (case when right(binlocation) in ('A', 'B', 'C', 'D' then 1 else 2 end),
left(binlocation, 1),
len(binlocation),
binlocation
是嵌套列表。每个元素都有两个data.frames。因此它是[[2]] * [[2]]嵌套列表。
given
我想将其展平为一个维度,因此它将是一个包含4个元素的列表,每个元素都是data.frame。结果将是...
given<-replicate(2,list(data.frame(unlist(replicate(10,sample(c(0.2,0.3,0.4,0.1),2,replace=FALSE),simplify=FALSE)),ncol=2)))
colnames(given[[1]])<-c('a','b')
colnames(given[[2]])<-c('a','b')
nested<-list(given, given)
nested
[[1]]
[[1]][[1]]
a b
[1,] 0.3 0.3
[2,] 0.2 0.4
[3,] 0.1 0.2
[4,] 0.3 0.3
[5,] 0.3 0.4
[6,] 0.1 0.2
[7,] 0.3 0.4
[8,] 0.2 0.3
[9,] 0.1 0.3
[10,] 0.3 0.4
[[1]][[2]]
a b
[1,] 0.3 0.2
[2,] 0.4 0.4
[3,] 0.2 0.4
[4,] 0.4 0.1
[5,] 0.1 0.4
[6,] 0.4 0.3
[7,] 0.1 0.4
[8,] 0.4 0.2
[9,] 0.2 0.4
[10,] 0.4 0.2
[[2]]
[[2]][[1]]
a b
[1,] 0.3 0.3
[2,] 0.2 0.4
[3,] 0.1 0.2
[4,] 0.3 0.3
[5,] 0.3 0.4
[6,] 0.1 0.2
[7,] 0.3 0.4
[8,] 0.2 0.3
[9,] 0.1 0.3
[10,] 0.3 0.4
[[2]][[2]]
a b
[1,] 0.3 0.2
[2,] 0.4 0.4
[3,] 0.2 0.4
[4,] 0.4 0.1
[5,] 0.1 0.4
[6,] 0.4 0.3
[7,] 0.1 0.4
[8,] 0.4 0.2
[9,] 0.2 0.4
[10,] 0.4 0.2
我尝试了[[1]]
a b
[1,] 0.3 0.3
[2,] 0.2 0.4
[3,] 0.1 0.2
[4,] 0.3 0.3
[5,] 0.3 0.4
[6,] 0.1 0.2
[7,] 0.3 0.4
[8,] 0.2 0.3
[9,] 0.1 0.3
[10,] 0.3 0.4
[[2]]
a b
[1,] 0.3 0.2
[2,] 0.4 0.4
[3,] 0.2 0.4
[4,] 0.4 0.1
[5,] 0.1 0.4
[6,] 0.4 0.3
[7,] 0.1 0.4
[8,] 0.4 0.2
[9,] 0.2 0.4
[10,] 0.4 0.2
[[3]]
a b
[1,] 0.3 0.3
[2,] 0.2 0.4
[3,] 0.1 0.2
[4,] 0.3 0.3
[5,] 0.3 0.4
[6,] 0.1 0.2
[7,] 0.3 0.4
[8,] 0.2 0.3
[9,] 0.1 0.3
[10,] 0.3 0.4
[[4]]
a b
[1,] 0.3 0.2
[2,] 0.4 0.4
[3,] 0.2 0.4
[4,] 0.4 0.1
[5,] 0.1 0.4
[6,] 0.4 0.3
[7,] 0.1 0.4
[8,] 0.4 0.2
[9,] 0.2 0.4
[10,] 0.4 0.2
程序包的rlist
函数,但是没有用。它打印出了变量的名称,而其他功能(例如list.flatten
也不起作用。
非常感谢您的帮助。