matvec {statmod} | R Documentation |
Multiply the rows or columns of a matrix by the elements of a vector.
matvec(M, v)
vecmat(v, M)
M |
numeric matrix, or object which can be coerced to a matrix. |
v |
numeric vector, or object which can be coerced to a vector. Length should match the number of columns of |
matvec(M,v)
is equivalent to M %*% diag(v)
but is faster to execute.
Similarly vecmat(v,M)
is equivalent to diag(v) %*% M
but is faster to execute.
A matrix of the same dimensions as M
.
Gordon Smyth
A <- matrix(1:12,3,4)
A
matvec(A,c(1,2,3,4))
vecmat(c(1,2,3),A)