add_matrices: Matrix addition

View source: R/math_funcs.R

add_matricesR Documentation

Matrix addition

Description

Add matrices together, specifying na.rm=TRUE or FALSE for each cell that has at least one finite value across corresponding cells in all matrices. Cells that have no finite values for any matrix will be set to empty_val (default NaN).

Usage

add_matrices(..., na.rm = TRUE, empty_val = NaN)

Arguments

...

Numeric matrices to add together (they must be the same size)

na.rm

Logical value, remove NA before calculating?

empty_val

Numeric value to use in cells that have no finite data across corresponding cells in all matrices

Value

The numeric matrix that is the sum of the input matrices (same shape)

Examples

A <- matrix(c(1:11, NA), nrow=4)
B <- matrix(c(1:4, NA, 6:11, NA), nrow=4)
C <- matrix(c(NA, NA, 3:11, NA), nrow=4)
add_matrices(A, B, C)

BIO-RSG/oceancolouR documentation built on April 30, 2024, 7:54 a.m.