View source: R/matrix_add_by_name.R
matrix_add_by_name | R Documentation |
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.
matrix_add_by_name(M, ...)
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. |
A matirx.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.