I have a matrix m and a vector v. I would like to multiply first column of matrix m by the first element of vector v, and
As @Arun points out, I don't know that you'll beat your solution in terms of time efficiency. In terms of code understandability, there are other options though:
One option:
> mapply("*",as.data.frame(m),v)
V1 V2 V3
[1,] 0.0 0.0 0.0
[2,] 1.5 0.0 0.0
[3,] 1.5 3.5 0.0
[4,] 1.5 3.5 4.5
And another:
sapply(1:ncol(m),function(x) m[,x] * v[x] )