I am looking for a solution to this problem: I have a list of such lists
sample = list("element1" = list("term1"=0.5, "term2"=1, "term3"= 4, "term1"= 0.5), "element2" = list("term23"=5, "term1"=2, "term23"=4))
For each list of the external list, I would like to summarize the values ββwith the same name. Thus, the desired result
desired_output = list("element1" = list("term1"=1, "term2"=1, "term3"= 4), "element2" = list("term23"=9, "term1"=2))
Actually, I was thinking of using something like this
result = lapply(sample, function(l) aggregate(l, by = list(names(l)), FUN = sum))
but it gives me an error. Any ideas on this? Thanks in advance.
source share