I have two lists
m = list( 'a' = list( 'b' = list( 1, 2 ), 'c' = 3, 'b1' = 4, 'e' = 5 ) )
n = list( 'a' = list( 'b' = list( 10, 20 ), 'c' = 30, 'b1' = 40 ), 'f' = 50 )
Where the structure of m is:
List of 1
$ a:List of 4
..$ b :List of 2
.. ..$ : num 1
.. ..$ : num 2
..$ c : num 3
..$ b1: num 4
..$ e : num 5
And the structure of n is:
List of 2
$ a:List of 3
..$ b :List of 2
.. ..$ : num 10
.. ..$ : num 20
..$ c : num 30
..$ b1: num 40
$ f: num 50
Want a combined output like this. Also the solution should be general for deeply nested lists.
Expected output :
List of 2
$ a:List of 4
..$ b :List of 4
.. ..$ : num 1
.. ..$ : num 2
.. ..$ : num 10
.. ..$ : num 20
..$ c : num [1:2] 3 30
..$ b1: num [1:2] 4 40
..$ e : num 5
$ f: num 50
Have seen this, but it is not general enough for deeply nested lists
Here is a recursive way to do it:
In case you have multiple nested lists (
m1
,m2
andm3
, for example) to merge,Reduce
could be helpful: