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

______________________________________________
R-help@r-project.org 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 via email to