[R] vectorization of groups of dot products

Rossi, Peter E. Peter.Rossi at chicagogsb.edu
Fri Jan 6 22:56:25 CET 2006


 
I have a set of n vectors, x_1, ..., x_n, of the same length.
I would like to form the vector of dot products -- x_1'x_1, ..., x_n'x_n

the fastest way I can think to do this is to put the vectors into a
matrix
and do 

diag(crossprod(X))

however, this seems to be very wasteful since this computes n(n+1)/2-n
unnecessary
dot products.

Is there a better way using existing functions in R?

thanks!

peter


................................
  Peter E. Rossi
 Joseph T. and Bernice S. Lewis Professor of Marketing and Statistics
 Editor, Quantitative Marketing and Economics
 Rm 353, Graduate School of Business, U of Chicago
 5807 S. Woodlawn Ave, Chicago IL 60637, USA
 Tel: (773) 702-7513   |   Fax: (773) 834-2081




More information about the R-help mailing list