I have two lists, whose elements have partially overlapping names, which I need to merge/combine together into a single list, element by element:
My question is rela
You can use lapply
operating on the keys to do this merge:
keys <- unique(c(names(l.1), names(l.2)))
setNames(lapply(keys, function(key) list(c(l.1[[key]][[1]], l.2[[key]][[1]]),
c(l.1[[key]][[2]], l.2[[key]][[2]]))),
keys)
# $a
# $a[[1]]
# [1] 10 20
#
# $a[[2]]
# [1] 1 0
#
# $b
# $b[[1]]
# [1] 10 20 30
#
# $b[[2]]
# [1] 1 2 3
#
# $c
# $c[[1]]
# [1] 9 12 13
#
# $c[[2]]
# NULL