Re: [R] multiplication question

From: N. Lapidus <n.lapidus_at_gmail.com>
Date: Wed, 02 Jul 2008 23:02:41 +0200

Hi Murali,

Just an idea, probably not the best :

x<-1:4
y<-1:6
z<-matrix(1:(length(x)*length(y)),nrow=length(x))

I <- matrix(1,nrow=length(x),ncol=length(y)) I[row(I)==col(I)] <- 0

sum (outer (x, y, '*') * I)
sum (outer (x, y, '*') * z * I)

Hope this helps,

Nael

On Wed, Jul 2, 2008 at 6:30 PM, Murali Menon <feanor0_at_hotmail.com> wrote:

>
> 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]]
>
>
> ______________________________________________
> 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.
>
>

        [[alternative HTML version deleted]]



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 - 21:19:01 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