R中用于“连接”/“拼接”单词列表的函数。

huangapple go评论88阅读模式
英文:

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 &lt;- Map(c,A,B)

or using mapply()

C &lt;- mapply(c,A,B,SIMPLIFY = F)

such that

&gt; C
[[1]]
[1] &quot;Flower&quot; &quot;Car&quot;    &quot;Blue&quot;  

[[2]]
[1] &quot;Moto&quot;  &quot;Black&quot; &quot;Red&quot; 

huangapple
  • 本文由 发表于 2020年1月3日 18:44:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定