Skip to content
Prev 276488 / 398506 Next

Doing dist on separate objects in a text file

On Nov 5, 2011, at 7:20 PM, ScottDaniel wrote:

            
I'm having trouble figuring out what you mean by "separating the  
objects". Each row is a separate reading, and I think you just want  
pairwise distances, right?
I don't think so. You need to read this file into a data.frame which  
should be fairly trivial with read.table is you specify the  
header=TRUE parameter.
Then assuming there is now a data.frame named "dat" with those values:

dist( cbind(dat$X, dat$Y))

One stumbling block might have been recognizing that the dist function  
will not work with two x and y arguments but rather requires a matrix  
(or something coercible to a matrix)  as its first argument. This  
would also have worked:

dist(dat[ , c("X", "Y")])