Skip to content
Prev 314357 / 398502 Next

How to multiple the vector and variables from dataframe

At Sun, 30 Dec 2012 16:28:44 +0000,
Andrius Druzinis wrote:
I think you mean multiplied by element.  

Here's a better solution using t to transpose the matrix:

dat=data.frame(x1=1:3, x2=11:13)
 as.matrix(dat)
     x1 x2
[1,]  1 11
[2,]  2 12
[3,]  3 13
t(as.matrix(dat)) * c(2, 3)
   [,1] [,2] [,3]
x1    2    4    6
x2   33   36   39