是否有一些很好的设计可以在嵌套结构中调用数据,例如
a<-list(list(LETTERS[1:3],LETTERS[1:3]),list(LETTERS[4:6]))
lapply(a,function(x) lapply(x, function(x) x))
但是不能选择列表。
答案 0 :(得分:1)
递归lapply
... a.k.a rapply
?
rapply( a , c )
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"
答案 1 :(得分:1)
不如@ SimonO101的回答,但只是提供替代方案,你可以使用do.call
> do.call(c,do.call(c, a))
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"
还使用Reduce
> do.call(c, Reduce(c, a))
[1] "A" "B" "C" "A" "B" "C" "D" "E" "F"