Hello,

Try the following.

t(sapply(seq_along(w), function(i) mat1[i,]*w[i]))

Hope this helps,

Rui Barradas
Em 16-11-2012 16:34, frespider escreveu:
Hi

Can someone show me an easy way to multiple a weighted vector with an
matrix?

example below
mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8)
w <- 1/1:10

I want the first element in w to be multiplied by the first row of mat1 and
2nd element in w to be multiplied with the 2nd row and so on.

I have huge matrix is there an easy way other than diag(w)%*%mat1

Thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-Vector-with-matrix-in-R-tp4649764.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to