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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.