To multiply rows of a matrix by a vector, you can use the sweep() function from the base package as follows:
mat <- matrix(rep(1:3,each=5),nrow=3,ncol=5,byrow=TRUE)
mat
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 1 1 1
[2,] 2 2 2 2 2
[3,] 3 3 3 3 3
vec <- 1:5
Use sweep to apply the vector with the multiply (`*`) function across columns where MARGIN is a vector giving the subscripts which the function will be applied over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1, 2) indicates rows and columns.i.e.,
> sweep(mat, MARGIN=2, vec, `*`)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 2 4 6 8 10
[3,] 3 6 9 12 15