[R] Matrix element-by-element multiplication
R. Michael Weylandt
michael.weylandt at gmail.com
Sat Nov 5 02:10:27 CET 2011
Did you even try?
a <- 1:3
x <- matrix(c(1,2,3,2,4,6,3,6,9),3)
a*x
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 8 12
[3,] 9 18 27
Michael
On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen <syen at utk.edu> wrote:
> is there a way to do element-by-element multiplication as in Gauss
> and MATLAB, as shown below? Thanks.
>
> ---
> a
>
> 1.0000000
> 2.0000000
> 3.0000000
> x
>
> 1.0000000 2.0000000 3.0000000
> 2.0000000 4.0000000 6.0000000
> 3.0000000 6.0000000 9.0000000
> a.*x
>
> 1.0000000 2.0000000 3.0000000
> 4.0000000 8.0000000 12.000000
> 9.0000000 18.000000 27.000000
>
>
> --
> Steven T. Yen, Professor of Agricultural Economics
> The University of Tennessee
> http://web.utk.edu/~syen/
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list