Here is one way of doing it:
> x <- read.table(textConnection("A A 0
+ A B .5
+ A C .25
+ B C .5"), as.is=TRUE)
> closeAllConnections()
> # get the unique names
> x.names <- sort(unique(c(x[[1]], x[[2]])))
> # create a matrix of the right size and put names on it
> x.dist <- matrix(0, length(x.nam
Hello,
Is there an easy function for switching list to matrix. My list is of
genetic distances between species pairs:
A A 0
A B .5
A C .25
B C .5
and I want a distance matrix such as:
A B C
A 0 .5 .25
B .5 0 .5
C .25 .5 0
for use in a mantel test.
Thank you for the help!
cheers,
charl
2 matches
Mail list logo