If a is m x r and b is n x r then 

   apply(outer(a,t(b),"-"),c(1,4),function(x)sqrt(sum(diag(x*x))))

is the m x n matrix of distances between the m rows of a and 
n rows of b.

Modify, as necessary, if you want distances other than euclidean.

---
Date: Tue, 6 Jan 2004 13:07:41 -0500 
From: <[EMAIL PROTECTED]>
To: Erin Hodgess <[EMAIL PROTECTED]> 
Cc: <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> 
Subject: Re: [R] dist(x,y) 

 
 
Hi Erin,

CLARIFICATION: I am looking for function which can calculate distances 
between
rows in two different matrices (not in the same matrix as dist).
Of course I can get the desired result by using rbind() and fiddling with 
indices of the result, which I already did,
but I wonder if there is a function (or some variant of dist), which does 
it directly ?

Ryszard





Erin Hodgess <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
01/06/2004 12:41 PM


To: [EMAIL PROTECTED]
cc: 
Subject: [R] dist(x,y)


Hi Ryszard!

There is a dist function in R.
It's in the mva package.
You can set the kind of distance that you want.

Thanks,
Erin
mailto:[EMAIL PROTECTED]

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to