以递归方式从多个列表中cbind项目

the*_*ail 5 join r list cbind

鉴于三个(或n列表):

one   <- list(a=1:2,b="one")
two   <- list(a=2:3,b="two")
three <- list(a=3:4,b="three")
Run Code Online (Sandbox Code Playgroud)

为了得到这个结果,cbindn列表中列出每个列表项的更有效方法是什么?

mapply(cbind,mapply(cbind,one,two,SIMPLIFY=FALSE),three,SIMPLIFY=FALSE)

$a
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4

$b
     [,1]  [,2]  [,3]   
[1,] "one" "two" "three"
Run Code Online (Sandbox Code Playgroud)

当这工作好n23,但很快将成为可笑复杂.这有更有效的变化吗?我在SO上看过类似的问题,但一直在努力调整它们.

mne*_*nel 7

使用ReduceMap(Map作为一个简单的包装mapply(..., SIMPLIFY = FALSE)

Reduce(function(x,y) Map(cbind, x, y),list(one, two,three))
Run Code Online (Sandbox Code Playgroud)

Reduce在R中使用或使用大多数函数式编程基函数时,通常无法传递参数,...因此通常需要编写一个小的匿名函数来执行您想要的操作.


flo*_*del 6

或者像这样:

mapply(cbind, one, two, three)
Run Code Online (Sandbox Code Playgroud)

或者像这样:

mylist <- list(one, two, three)
do.call(mapply, c(cbind, mylist))
Run Code Online (Sandbox Code Playgroud)