One of the options: meltand listto data.frame merge, enter them rowSumsin the numeric columns and go back to list.
library(reshape2)
d1 <- merge(melt(l1), melt(l2), by='L1', all=TRUE)
setNames(as.list(rowSums(d1[-1], na.rm=TRUE)), d1$L1)
Or we create unique namesboth 'l1' and 'l2' ('nm1'). Set loop "nm1", replaceNULL elements with 0 and execute +.
nm1 <- union(names(l1), names(l2))
lapply(nm1, function(x) {v1 <- l1[[x]]
v2 <- l2[[x]]
replace(v1, is.null(v1), 0) +
replace(v2, is.null(v2), 0)
})
akrun source
share