[R] Vector multiplication

Duncan Murdoch murdoch.duncan at gmail.com
Sun Oct 17 13:26:44 CEST 2010


Ron Michael wrote:
> Is there any operator in R, which will multiply each possible combination of the elements of 2 vectors? Suppose I have 2 vectors (1,2) and (1,2,3). If I multiply those 2, I should get:(1,2,3,2,4,6)

See ?outer.  For example,

as.vector(outer(1:3, 1:2))

(but the results are more useful without as.vector()).

Duncan Murdoch



More information about the R-help mailing list