Say I have a named nested list l consisting of sub-lists of named numeric vectors, each of length 1:
l <- list("L1" = list('a' = 1, 'b' = 2), "L2" = list('a'= 2, 'c' = 1, 'd' = 1))
I am struggling to find a way in base R to apply a function such as sum for all matching sub-list with similar name (e.g. l$L1$a and l$L2$a whose sum would be 3).
The result from applied using sum in l would be for instance a named vector res:
> res
a b c d
3 2 1 1
In (my) real life the list l has variable and unknown numbers and lengths of sub-lists L1, L2, ... , and similar, the names and numbers of the numeric vectors to be summed (a, b, ...) are also variable and unknown. However, the depth of the list is always as shown.