Re: [R] multiplication question
The answer to your first question is sum(x)8sum(y) - sum(x*y) and for the second one x %*% R %*% y - sum(x*y*diag(R)) --- On Thu, 3/7/08, Murali Menon [EMAIL PROTECTED] wrote: From: Murali Menon [EMAIL PROTECTED] Subject: [R] multiplication question To: [EMAIL PROTECTED] Received: Thursday, 3 July, 2008, 2:30 AM 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@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. __ R-help@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.
Re: [R] multiplication question
Thanks for your help, folks. The sum of (outer product less the diagonal) works. (In the original post, I guess I should have specified 'pair-wise product' of two vectors to be clearer). Date: Thu, 3 Jul 2008 00:25:10 +0300From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [R] multiplication questionCC: [EMAIL PROTECTED] example ...x - 1:5 ; y- 6:8(m - x %o% y) # is this what you mean by product of two vectors?sum(m[row(m)!=col(m)]) # or ...sum(m)-sum(diag(m)) On Wed, Jul 2, 2008 at 7:30 PM, Murali Menon [EMAIL PROTECTED] 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 computeSum (X[i] * Y[j])i != jwhere i != jalso, what if i wantedSum (X[i] * Y[j] * R[i, j])i != jwhere R is a matrix?thanks,[EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. _ [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@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.
[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]] __ R-help@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.
Re: [R] multiplication question
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Murali Menon Sent: Thursday, 3 July 2008 4:31 a.m. To: [EMAIL PROTECTED] 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@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.
Re: [R] multiplication question
Try something about like this: v1 %o% v2 - diag(v1*v2) On Wed, Jul 2, 2008 at 1:30 PM, Murali Menon [EMAIL PROTECTED] 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@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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@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.
Re: [R] multiplication question
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 [EMAIL PROTECTED] 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@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@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.
Re: [R] multiplication question
I'm sorry: sum(v1 %o% v2 - diag(v1*v2)) On Wed, Jul 2, 2008 at 6:03 PM, Henrique Dallazuanna [EMAIL PROTECTED] wrote: Try something about like this: v1 %o% v2 - diag(v1*v2) On Wed, Jul 2, 2008 at 1:30 PM, Murali Menon [EMAIL PROTECTED] 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@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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@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.
Re: [R] multiplication question
for example ... x - 1:5 ; y- 6:8 (m - x %o% y) # is this what you mean by product of two vectors? sum(m[row(m)!=col(m)]) # or ... sum(m)-sum(diag(m)) On Wed, Jul 2, 2008 at 7:30 PM, Murali Menon [EMAIL PROTECTED] 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@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@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.