I have a matrix mat
and a vector v
. I would like to multiply first column of matrix mat
by first element of vector v
and multiply the second column of matrix mat
by second element of vector v
. I can do it as shown. How can I do this faster in R since we get a big matrix?
mat = matrix(rnorm(1500000), ncol= 100)
v= rnorm(100)
> system.time( mat %*% diag(v))
user system elapsed
0.02 0.00 0.02
See Question&Answers more detail:os