/ Home
S-Archive Download Script
matvec, vecmat Multiple a matrix by vector
DESCRIPTION
Multiply the rows or columns of a matrix by the elements of a vector.
 
USAGE
matvec(M, v)
vecmat(v, M)
 
REQUIRED ARGUMENTS
M matrix, or object which can be coerced to a matrix.
v vector, or object which can be coerced to a vector. Length should match the number of columns of M (for matvec) or the number of rows of M (for vecmat)
 
VALUE
A matrix of the same dimensions as M.
 
DETAILS
matvec(M,v)  is equivalent to  M %*% diag(v), while
vecmat(v,M)  is equivalent to  diag(v) %*% M.
 
EXAMPLES
> A <- matrix(1:12,3,4)
> A
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> matvec(A,c(1,2,3,4))
     [,1] [,2] [,3] [,4]
[1,]    1    8   21   40
[2,]    2   10   24   44
[3,]    3   12   27   48
> vecmat(c(1,2,3),A)
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    4   10   16   22
[3,]    9   18   27   36

 

S-Archive Download Script

Gordon Smyth. Copyright © 1996-2016. Last modified: 10 February 2004