[R] A factor times a matrix

arun smartpink111 at yahoo.com
Tue Sep 17 05:06:58 CEST 2013


Hi,
 t(a*t(b))
#     [,1] [,2]
#[1,]    1    8
#[2,]    2   10
#[3,]    3   12

A.K.


Hello eveybody, 

I have a vector a and a matrix b : 
> a 
[1] 1 2 
> b 
[,1] [,2] 
[1,] 1 4 
[2,] 2 5 
[3,] 3 6 

With simple multiplication I get : 
> a * b 
[,1] [,2] 
[1,] 1 8 
[2,] 4 5 
[3,] 3 12 

I would like to have that : 
[,1] [,2] 
[1,] 1 8 
[2,] 2 10 
[3,] 3 12 

Fo now I use replicate bu I would like to do this in a simple way. 

Do you have a solution ? 

Thank you in advance



More information about the R-help mailing list