让x
为向量列表:
a <-list( c(1,2,3), c(4,5,6), c(7,8) ,c(9) )
b <-list(c(11,22,33),c(44,55,66), c(77,88) ,c(99) )
x <- list(a=a,b=b)
我想要的输出如下:
>foo(x)
list(c(1,2,3,11,22,33),c(4,5,6,44,55,66),c(7,8,77,88),c(9,99)
答案摘要
Map(c, a, b)
do.call(Map, c(f = "c", unname(x)))
mapply(function(i, j){c(i,j)}, a, b)
答案 0 :(得分:2)
这是mapply()
a <-list( c(1,2,3), c(4,5,6), c(7,8) ,c(9) )
b <-list(c(11,22,33),c(44,55,66), c(77,88) ,c(99) )
mapply(function(i, j){c(i,j)}, a, b)
#> [[1]]
#> [1] 1 2 3 11 22 33
#>
#> [[2]]
#> [1] 4 5 6 44 55 66
#>
#> [[3]]
#> [1] 7 8 77 88
#>
#> [[4]]
#> [1] 9 99