Hello,

To complete Arun's response, you also have:

> sweep(b,2,a,'*')
     [,1] [,2]
[1,]    1    8
[2,]    2   10
[3,]    3   12

or

> b %*% diag(a)
     [,1] [,2]
[1,]    1    8
[2,]    2   10
[3,]    3   12

Regards,
Pascal



2013/9/17 arun <smartpink...@yahoo.com>

> 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
>
> ______________________________________________
> 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.
>



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

        [[alternative HTML version deleted]]

______________________________________________
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