[R] distance matrix as text file - how to import?
Paul Johnson
pauljohn32 at gmail.com
Tue Apr 8 22:26:31 CEST 2008
On Tue, Apr 8, 2008 at 1:50 PM, Hans-Jörg Bibiko <bibiko at eva.mpg.de> wrote:
> 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
>
Try this! I put your test data in "text.txt" and voila:
mat <- matrix(0, 3,3)
mat[row(mat) >= col(mat)] <- scan("test.txt")
I found this Idea after "RSiteSearch("scan triangular") led to this
item as the very first link:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/22369.html
PJ
--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas
More information about the R-help
mailing list