# Transformation of matrix with missing values for hierarchical clustering

Comparing different variables, I got a matrix with lots of missing values.

How do I have to transform the matrix below for hierarchical clustering?

What I have already tried:

x = read.csv("xyz.csv", sep = ";", row.names = 1, header = TRUE)
x[is.na(x)] = FALSE

# transform to correlation matrix
x = cor(t(x), method = "pearson")

# elbow method
fviz_nbclust(x, FUN = hcut, method = "wss")

# cluster with ward method
hc = hclust(dist(x), method = "ward.D2")

# show clusters
rect.hclust(hc,k=3, border="red")
plot(hc)


This clustering result looks wrong:

dissimilarity matrix

Right keyword for further search "dissimilarity matrix". Now i tried to transform the matrix into a distance matrix.


x= as.dist(x, diag = TRUE)
hc = hclust(dist(x), method = "ward.D2")
plot(hc)


that´s not a solution yet

• That isn't a solution. It's just hiding the error. The meaning of the result is likely completely messed up. Hacking random functions together without understanding what they do never was a good idea... – Anony-Mousse Jul 1 at 5:58
• thanks for that hint. i will dive deeper into that cluster method. – bartman99 Jul 2 at 10:16