# [R] Basic vector operations was: Function toapproximate complex integral

Doran, Harold HDoran at air.org
Wed Apr 19 21:59:01 CEST 2006

```Yup, thanks, all . I tried outer but didn't sum the elements before I
posted. Thanks

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Marc Schwartz
(via MN)
Sent: Wednesday, April 19, 2006 3:46 PM
To: Doran, Harold
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Basic vector operations was: Function toapproximate
complex integral

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

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help