[R] dist() between groups of data
Henrik Parn
henrik.parn at bio.ntnu.no
Thu Feb 23 17:40:19 CET 2006
Dear all,
I have a data set with x and y positions of nests. Each nest can be
grouped according to a factor z. I have made a small dummy data set,
where the grouping variable z is 0 or 1:
x <- runif(6)
y <- runif(6)
z <- rep(c(0,1), each=3)
xyz <- cbind(x,y,z)
xyz
x y z
[1,] 0.7176801 0.760944688 0
[2,] 0.2377928 0.080622524 0
[3,] 0.9450770 0.022039470 0
[4,] 0.8725492 0.971996677 1
[5,] 0.6356198 0.001569859 1
[6,] 0.8949670 0.066044377 1
First of all, I suppose that this is the correct way to calculate the
Euclidean distance between /all/ nests:
xy <- cbind(x,y)
d.all <- dist(xy)
However, I would like to obtain a distance matrix for distances between
nests belonging to certain groups. For example "calculate all distances
from nests where z equals something, to nests where z equals something
else".
Is it best to split the data in two matrices according to the value of z
in the two groups to be compared, and then try to follow the suggestions
by Gabor Grothendieck* Date:* Wed 07 Jan 2004 - 15:16:37 EST , or are
there other ways that can be applied straight to one matrix?
Thanks in advance!
Henrik
--
************************
Henrik Pärn
Department of Biology
NTNU
7491 Trondheim
Norway
+47 735 96282 (office)
+47 909 89 255 (mobile)
+47 735 96100 (fax)
More information about the R-help
mailing list