On Wed, 2006-04-19 at 15:25 -0400, Doran, Harold wrote:
> Dear List
> 
> I apologize for the multiple postings. After being in the weeds on this
> problem for a while I think my original post may have been a little
> cryptic. I think I can be clearer. Essentially, I need the following
> 
> a <- c(2,3)
> b <- c(4,5,6)
> 
> (2*4) + (2*5) + (2*6) + (3*4) + (3*5) +(3*6)
> 
> But I do not know of a built in function that would do this. Any
> suggestions?

<SNIP>

Unless I am missing something, how about:

> sum(a %x% b)
[1] 75

See ?"%x%"

You could also use outer():

> sum(outer(a, b, "*"))
[1] 75

See ?outer

HTH,

Marc Schwartz

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to