A basic/common class in R is called \"dist\"
, and is a relatively efficient representation of a symmetric distance matrix. Unlike a \"matrix\"
object,
You can acces the atributes of any object with str()
for a "dist" object of some of my data (dist1), it look like this:
> str(dist1)
Class 'dist' atomic [1:4560] 7.3 7.43 7.97 7.74 7.55 ...
..- attr(*, "Size")= int 96
..- attr(*, "Labels")= chr [1:96] "1" "2" "3" "4" ...
..- attr(*, "Diag")= logi FALSE
..- attr(*, "Upper")= logi FALSE
..- attr(*, "method")= chr "euclidean"
..- attr(*, "call")= language dist(x = dist1)
you can see that for this particular data set, the "Labels" attribute is a character string of length = 96 with numbers from 1 to 96 as characters.
you could change directly that character string doing:
> attr(dist1,"Labels") <- your.labels
"your.labels" should be some id. or factor vector, presumably in the original data from with the "dist" object was made.