[R] distance matrix

Jose Andres jaa53 at cornell.edu
Sat Jul 29 00:13:30 CEST 2006


Hi all,

I have a set of points (1...n) each of them defined on a 3D space  
(i.e. for each point I do have  x,y,z coordinates), and I would like  
to generate a mean pairwise geometrical distance between them. Is  
there anyway I can do this with R?

Conceptually is really simple. First I have to generate a distance  
matrix (let's say "distmat") of pairwise distances (d= sqrt((x1-x2)^2 
+ (y1-y2)^2+(z1-z2)^2) and then calculate the mean -- mean.matrix 
(distmat) -- . However, I do not know how I can generate the distance  
matrix using R. I'd really appreciate all your suggestions/comments.

So, I have
	x		y		z

1	x1		y1		z1

2	x2		y2		z2

:	:		:		:
n	xn		yn		zn

and need

		1		2	..	n
1		-

2		d12		-

:
n		d1n		d2n		-

So I can calculate mean din



Thanks in advance!!!!!

Best,

/Jose



More information about the R-help mailing list