matrix_add_by_name: Add Matrices by Names of Columns and Rows

View source: R/matrix_add_by_name.R

matrix_add_by_nameR Documentation

Add Matrices by Names of Columns and Rows

Description

Add together some matrices by names of columns and rows. Those matrices may have distinct sizes. All matrices should not have column names and row names other than those of the first matrix.

Usage

matrix_add_by_name(M, ...)

Arguments

M

a matrix with column names and row names.

...

some matrices with column names and row names which constitute subsets of those of M. If there is a vector, it will be converted to a matrix of one column and the column will be named after the vector.

Value

A matirx.

Examples

M <- matrix(0, 5, 5)
colnames(M) <- paste("c", 1:5, sep = "")
rownames(M) <- paste("r", 1:5, sep = "")

M2 <- matrix(1:9, 3, 3)
colnames(M2) <- c("c2", "c3", "c5")
rownames(M2) <- c("r1", "r2", "r4")

matrix_add_by_name(M, M2)

c1 <- c(r1 = 1, r3 = 2)
matrix_add_by_name(M, c1)
matrix_add_by_name(M, c1, M2)

GE documentation built on Nov. 8, 2023, 9:07 a.m.

Related to matrix_add_by_name in GE...