[R] distance matrix as text file - how to import?

Hans-Jörg Bibiko bibiko at eva.mpg.de
Tue Apr 8 20:50:53 CEST 2008


Dear all,

I have -hopefully- a tiny problem.

I was sent a text file containing a distance matrix à la:

1
2 3
4 5 6

Now I wanted to import these data into a dist object to, let's say,  
do 'plot(hclust(v))'.

My first naïve approach was to scan the text file in order to get a  
vector v. Then I did:

class(v) <- "dist"
attr(v, "Size") <- 4

But, of course, I got this:

1
2 4
3 5 6

I wonder if there's an elegant way to do it. The only way I know of  
is very very stony one.

I'd be very appreciated for any hint.

Cheers,

--Hans



More information about the R-help mailing list