[R-sig-Geo] inter-point distance calcs

Kamran Safi ksafi at orn.mpg.de
Mon Aug 10 21:09:28 CEST 2009


Maybe a little too complicated, but I had it at hands:

d <- data.frame(x=sample(1:10, 5), y=sample(1:10, 5)) #create a sample 
data set
ss2 <- as.data.frame(as.matrix(dist(d))) #create a data.frame to extract 
row and column names
X <- rep(seq(1:length(row.names(ss2))), length(names(ss2))) #make a 
vector containing the X coordinate names
Y <- rep(seq(1:length(names(ss2))), length(row.names(ss2))) #the same for Y
Y <- sort(Y) #first sort
coords <- cbind(X, Y) #then cbind
data <- as.data.frame(cbind(coords, as.vector(as.matrix(dist(d))))) # 
add the data
data <- data[data$V3 >0,] #remove the distance to self


hope this solves it.

Kami


Jim Bouldin wrote:
> Last message got truncated somehow.  To repeat, I forgot to mention that I
> need to get the distances into the following format.  Using Dylan's example
> above:
>
> Point Pair      Distance
> 1-2             3.6 
> 1-3             6.4
> 1-4             9.2
> .               .
> .               .
> 3-4             .
> 3-4             .
> 4-5             3.2
>
> That is, I need to be able to create a column vector that labels each pair
> of points, which I can then cbin with the distance vector into a new matrix
> (I know how to create the distance vector, but not the identifier vector).
>  The point pair identifiers (labels) will come from a column in the
> original data matrix.
> Thanks
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3275 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090810/bc7079f9/attachment.bin>


More information about the R-sig-Geo mailing list