matrix_op.Rd
Matrix operations based on matching dimensions
matrix_op(m1, m2, op = `+`)
matrices with dimnames
the operation to be performed
nms1 <- letters[1:4]
mat1 <- matrix(1:8, nrow=4, ncol=4, dimnames=list(nms1, nms1))
nms2 <- letters[2:3]
mat2 <- matrix(11:18, nrow=2, ncol=4, dimnames=list(nms2, nms1))
matrix_op(mat1, mat2)
#> a b c d
#> a 1 5 1 5
#> b 13 19 17 23
#> c 15 21 19 25
#> d 4 8 4 8
matrix_op(mat1, mat2, `*`)
#> a b c d
#> a 1 5 1 5
#> b 22 78 30 102
#> c 36 98 48 126
#> d 4 8 4 8