I know this is a really basic question, sorry.
I want to multiply each row of a matrix by a vector. So I have:
mat=matrix(1,2,4)
vec=c(1,2,3,4)
#works but ugly:
new.mat=mat
for(i in 1:nrow(mat)){
new.mat[i,]=mat[i,]*vec
}
I thought I'd found the answer with 'apply' but I couldn't get it to work the same way.