Skip to content
Prev 315120 / 398528 Next

locating element in distance matrix

If you really have a matrix to begin with, yes. But if you generated it from
dist() or its relations, you would have to convert it to a matrix (roughly
doubling the memory needed). The various hierarchical cluster functions
usually want a dist object.
Class 'dist'  atomic [1:45] 3.84 4.09 3.64 4.94 4.33 ...
  ..- attr(*, "Size")= int 10
  ..- attr(*, "Diag")= logi TRUE
  ..- attr(*, "Upper")= logi TRUE
  ..- attr(*, "method")= chr "euclidean"
  ..- attr(*, "call")= language dist(x = x, diag = TRUE, upper = TRUE)

In dist(), diag=TRUE and upper=TRUE refer only to how the matrix is
displayed. It is still stored as a single vector:
1     2     3     4     5     6     7     8     9    10
1  0.000 3.843 4.094 3.643 4.935 4.328 4.288 6.205 6.197 2.181
2  3.843 0.000 5.085 5.171 5.067 3.788 4.384 5.770 7.113 2.830
3  4.094 5.085 0.000 3.571 4.548 4.103 3.532 3.917 6.470 3.734
4  3.643 5.171 3.571 0.000 3.821 3.843 3.667 5.513 5.176 3.294
5  4.935 5.067 4.548 3.821 0.000 4.815 3.465 5.918 6.138 4.764
6  4.328 3.788 4.103 3.843 4.815 0.000 2.794 3.937 5.475 3.023
7  4.288 4.384 3.532 3.667 3.465 2.794 0.000 4.075 5.251 4.010
8  6.205 5.770 3.917 5.513 5.918 3.937 4.075 0.000 5.511 5.152
9  6.197 7.113 6.470 5.176 6.138 5.475 5.251 5.511 0.000 6.168
10 2.181 2.830 3.734 3.294 4.764 3.023 4.010 5.152 6.168 0.000
[1] 3.843183
Error in dm[2, 1] : incorrect number of dimensions

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352