1

I have a simple distance matrix as such:

I tried making my own distance matrix:

 distances=matrix(c(0,  6.32,  11.3,     1,    10,  5.66,  4.24,
           6.32,     0,  6.32,  6.08,     6,  2.83,  3.16,
           11.3,  6.32,     0,  10.6,     2,  5.66,  7.07,
           1,  6.08,  10.6,     0,  9.22,     5,  3.61,
           10,     6,     2,  9.22,     0,  4.47,  5.83,
           5.66,  2.83,  5.66,     5,  4.47,     0,  1.41,
           4.24,  3.16,  7.07,  3.61,  5.83,  1.41,     0),nrow=7,   ncol=7, byrow = TRUE)

But this doesn't cluster

    > hc <- hclust(distances)
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed

I would like to create a dendrogram based on measuring the smallest distances between clusters. With the end product looking like this:

enter image description here

Any ideas? Help would be appreciated!

1 Answer 1

3

The input for hclust requires a dissimilarity structure as produced by ‘dist’, with matrix, you can convert it to a 'dist' object and then hclust and plot:

plot(hclust(as.dist(distances)))

enter image description here

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.