matmult {base} | R Documentation |
Multiplies two matrices, if they are conformable. If one argument is a vector, it will be promoted to either a row or column matrix to make the two arguments conformable. If both are vectors it will return the inner product.
a %*% b
a, b |
numeric or complex matrices or vectors. |
When a vector is promoted to a matrix, its names are not
promoted to row or column names, unlike as.matrix
.
The matrix product. Use drop
to get rid of dimensions
which have only one level.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
matrix
,
Arithmetic
,
diag
.
x <- 1:4 (z <- x %*% x) # scalar ("inner") product (1 x 1 matrix) drop(z) # as scalar y <- diag(x) z <- matrix(1:12, ncol = 3, nrow = 4) y %*% z y %*% x x %*% z