Re: [R] multiplication question

From: Peter Alspach <PAlspach_at_hortresearch.co.nz>
Date: Thu, 03 Jul 2008 08:54:04 +1200

Murali

I don't know about 'clever', but does this do what you want?

v1 <- 1:3
v2 <- 4:6
sum(matrix(rep(v1, length(v1)), nrow=length(v1))%*%v2)-sum(v1*v2)

Peter Alspach  

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Murali Menon
> Sent: Thursday, 3 July 2008 4:31 a.m.
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] multiplication question
>
>
> folks,
>
> is there a clever way to compute the sum of the product of
> two vectors such that the common indices are not multiplied together?
>
> i.e. if i have vectors X, Y, how can i compute
>
> Sum (X[i] * Y[j])
> i != j
>
> where i != j
>
> also, what if i wanted
>
> Sum (X[i] * Y[j] * R[i, j])
> i != j
>
> where R is a matrix?
>
> thanks,
>
> murali
>
>
> _________________________________________________________________
> Enter the Zune-A-Day Giveaway for your chance to win - day
> after day after day
>
> M_Mobile_Zune_V1
> [[alternative HTML version deleted]]
>
>

The contents of this e-mail are privileged and/or confidential to the named  recipient and are not to be used by any other person and/or organisation.  If you have received this e-mail in error, please notify the sender and delete  all material pertaining to this e-mail.



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. Received on Wed 02 Jul 2008 - 20:56:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jul 2008 - 21:32:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive