[R] fastest way to compute the squared Euclidean distance between two vectors in R
Jason Liao
jg_liao at yahoo.com
Thu Jan 31 03:28:26 CET 2008
I have a program which needs to compute squared Euclidean distance
between two vectors million of times, which the Rprof shows is the
bottleneck. I wondered if there is any faster way than my own simple
function
distance2 = function(x1, x2)
{
temp = x1-x2
sum(temp*temp)
}
I have searched the R-help archives and can not find anything except
when the arguments are matrices. Thanks for any lead.
Jason
Jason Liao, http://www.geocities.com/jg_liao
Associate Professor of Biostatistics
Drexel University School of Public Health
1505 Race Street, Mail Stop 1033
Bellet Building, 6th Floor
Philadelphia, PA 19102
phone 215-762-3934
____________________________________________________________________________________
Looking for last minute shopping deals?
More information about the R-help
mailing list