[英]Combine or merge recursively two list in R
I had this two lists: 我有两个清单:
firstList <- list(a = list(a_1 = 1:5,
a_2 = 5:10),
b = 10,
c = list(c_1 = 10:20,
c_2 = 20:30))
secondList <- list(b = 9999,
c = list(c_2 = 500:505))
I wonder to find an elegant function (few lines of code, no loops) such: 我想知道如何找到一个优雅的功能(几行代码,没有循环):
thirdList <- awesomeFx(firstList, secondList)
Gives me: 给我:
$a
$a$a_1
[1] 1 2 3 4 5
$a$a_2
[1] 5 6 7 8 9 10
$b
[1] 9999
$c
$c$c_1
[1] 10 11 12 13 14 15 16 17 18 19 20
$c$c_2
[1] 500 501 502 503 504 505
In other words, a function (o some way) that recursively replace elements within two lists. 换句话说,以某种方式递归替换两个列表中的元素的函数。
modifyList(firstList, secondList)
$a
$a$a_1
[1] 1 2 3 4 5
$a$a_2
[1] 5 6 7 8 9 10
$b
[1] 9999
$c
$c$c_1
[1] 10 11 12 13 14 15 16 17 18 19 20
$c$c_2
[1] 500 501 502 503 504 505
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.