【发布时间】:2020-04-21 22:25:03
【问题描述】:
R 中用于“求和”单词列表的函数,例如:
A = list (c ("Flower", "Car"), "Moto")
B = list ("Blue", c ("Black", "Red"))
结果是C
C = list (c ("Flower", "Car", "Blue"), c ("Moto", "Black", "Red"))
请帮帮我
【问题讨论】:
R 中用于“求和”单词列表的函数,例如:
A = list (c ("Flower", "Car"), "Moto")
B = list ("Blue", c ("Black", "Red"))
结果是C
C = list (c ("Flower", "Car", "Blue"), c ("Moto", "Black", "Red"))
请帮帮我
【问题讨论】:
这是一个基本的 R 解决方案,类似于@YOLO 的答案
C <- Map(c,A,B)
或使用mapply()
C <- mapply(c,A,B,SIMPLIFY = F)
这样
> C
[[1]]
[1] "Flower" "Car" "Blue"
[[2]]
[1] "Moto" "Black" "Red"
【讨论】:
你可以这样做:do.call(Map, c(c, list(A, B)))
purrr也一样:
purrr::map2(A,B,c)
[[1]]
[1] "Flower" "Car" "Blue"
[[2]]
[1] "Moto" "Black" "Red"
【讨论】: