[R] Odp: how to calculate the product of every two elements in two vectors

Petr PIKAL petr.pikal at precheza.cz
Mon Jul 26 08:13:33 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 23.07.2010 17:11:43:

> 
> Thanks in advance!
> 
> A=c(1, 2,3)
> B=c (9, 10, 11, 12)
> 
> I want to get C=c(1*9, 1*10, 1*11, 1*12, ....., 3*9, 3*10, 3*11, 3*12)?
> C is still a vector with 12 elements
> Is there a way to do that?

Maybe

as.vector(t(outer(A,B)))

Regards
Petr


> -- 
> View this message in context: 
http://r.789695.n4.nabble.com/how-to-calculate-
> the-product-of-every-two-elements-in-two-vectors-tp2300299p2300299.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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