Home > Blockchain >  Plotting a dendrogram
Plotting a dendrogram

Time:04-20

Im trying to plot a dendrogram with my data

dendogram <- hclust(distance)

but run into this error code;

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

I'm not entirely sure how to fix this so it works, so if anyone has any idea that would be appreciated. Please ask if theres anymore info you need, appreciate this question doesnt contain much extra. Code used below;

#euclidean distance matrix

distance <- dist(mydf, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
distance <- distance %>% as.matrix()

#dendrogram
dendogram <- hclust(distance)
plot(dendogram)

CodePudding user response:

Don't coerce "dist" object to matrix.

x <- matrix(rnorm(100), nrow = 5)
d <- dist(x)
dd <- hclust(d)  ## works fine
plot(dd)

enter image description here

hclust(as.matrix(d))  ## fails
# Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
#   missing value where TRUE/FALSE needed
  • Related