Skip to content
Prev 293549 / 398503 Next

Summing list with NA elements

Inelegant, but this is one way:

Reduce(function(e1, e2){e1[is.na(e1)] <- 0; e2[is.na(e2)] <- 0; (e1 + e2)}, x)

I.e., set the NAs to 0 before adding in the reduce function.

Michael
On Fri, May 4, 2012 at 5:19 AM, Evgenia <evgts at aueb.gr> wrote: