sumMatrix: Performs sum of matrices or vectors

View source: R/matrices.R

sumMatrixR Documentation

Performs sum of matrices or vectors

Description

Given a list of matrices, returns a single matrix in which element (i, j) is the sum of all corresponding elements (i, j) of all matrices in the list. Given a list of vectors, returns a single vector in which element i is the sum of all corresponding elements i of all vectors in the list.

Usage

sumMatrix(matricesList)

Arguments

matricesList

a list of numeric matrices with same dimensions

Value

A matrix in which element (i,j) is the sum of all corresponding elements (i,j) of all matrices in the original list

Examples

mat1 <- matrix(1:4, nrow = 2)
mat2 <- matrix(5:8, nrow = 2)
mat3 <- matrix(9:12, nrow = 2)
list_matrix <- list(mat1, mat2, mat3)
list_matrix

sumMatrix(list_matrix)


Leonardo-Bo/rgrids documentation built on July 27, 2024, 2:19 a.m.