[R] dist(x,y)
Gabor Grothendieck
ggrothendieck at myway.com
Wed Jan 7 05:16:37 CET 2004
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: <ryszard.czerminski at pharma.novartis.com>
To: Erin Hodgess <hodgess at gator.uhd.edu>
Cc: <r-help at stat.math.ethz.ch>, <r-help-bounces at stat.math.ethz.ch>
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 <hodgess at gator.uhd.edu>
Sent by: r-help-bounces at stat.math.ethz.ch
01/06/2004 12:41 PM
To: r-help at stat.math.ethz.ch
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:hodgess at gator.uhd.edu
More information about the R-help
mailing list