Quantcast

Species names in distance matrix

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Species names in distance matrix

Katharine Miller
I have a function that requires a distance matrix of class dist with
species names as row names.  For the life of me, I cannot figure out how to
get dist() to include species names.

I am sure this must be easy, because a lot of packages and functions out
there require dist objects to have row names.  Any help would be MUCH
appreciated.
- Katharine

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Species names in distance matrix

Peter Ehlers
On 2012-07-13 15:55, Katharine Miller wrote:
> I have a function that requires a distance matrix of class dist with
> species names as row names.  For the life of me, I cannot figure out how to
> get dist() to include species names.
>
> I am sure this must be easy, because a lot of packages and functions out
> there require dist objects to have row names.  Any help would be MUCH
> appreciated.
> - Katharine

You should be able to just set the 'Labels' attribute:

   x <- matrix(rnorm(100), nrow=5)
   d <- dist(x)
   attr(d, "Labels") <- LETTERS[1:5]

Alternatively, convert d to a matrix, assign rownames
and convert back to a dist:

   m <- as.matrix(d)
   rownames(m) <- letters[1:5]
   d1 <- as.dist(m)

Peter Ehlers

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...