英文:
A function in R for "joining"/"concantenating" word lists
问题
A function in R for "summing" word lists, example:
A = list(c("Flower", "Car"), "Moto")
B = list("Blue", c("Black", "Red"))
And the result is C
C = list(c("Flower", "Car", "Blue"), c("Moto", "Black", "Red"))
英文:
A function in R for "summing" word lists, example:
A = list (c ("Flower", "Car"), "Moto")
B = list ("Blue", c ("Black", "Red"))
And the result is C
C = list (c ("Flower", "Car", "Blue"), c ("Moto", "Black", "Red"))
Please help me
答案1
得分: 2
你可以使用以下方式进行操作:do.call(Map, c(c, list(A, B)))
使用purrr
也可以实现相同的效果:
purrr::map2(A, B, c)
[[1]]
[1] "Flower" "Car" "Blue"
[[2]]
[1] "Moto" "Black" "Red"
英文:
You can do: do.call(Map, c(c, list(A, B)))
The same with purrr
:
purrr::map2(A,B,c)
[[1]]
[1] "Flower" "Car" "Blue"
[[2]]
[1] "Moto" "Black" "Red"
答案2
得分: 2
这是一个基于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"
英文:
Here is a base R solution similar to the answer by @YOLO
C <- Map(c,A,B)
or using mapply()
C <- mapply(c,A,B,SIMPLIFY = F)
such that
> C
[[1]]
[1] "Flower" "Car" "Blue"
[[2]]
[1] "Moto" "Black" "Red"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论