Array or matrix addition in base R sets all sums in an element position to NA if any element in that position is NA in either of the arrays being added. In contrast, this function ignores NA values by default in its addition.
Usage
add_array_na.rm(ary1, ary2, na.rm = TRUE)
Arguments
- ary1, ary2
numeric arrays or matrices. The arrays to be added. They must be of the same dimension.
- na.rm
logical(1). TRUE (default) if missing values (NA
) should be ignored in the summation. If both elements in a given position are missing, then the result will be NA
.
Value
An array or matrix of the same dimensions as ary1
and ary2
whose values are the sums of ary1
and ary2
in each corresponding element.
Reduce(add_array_na.rm, list(x1, x2, x3))