Variables

merged2 <- merged %>% 
           remove_rownames %>% 
           column_to_rownames(var="Nom_Barri") %>% 
           select("n.tot.V1419","n.esp.V1419","n.ext.V1419","n.ue27-esp.V1419","n.ue27.V1419",
                  "hotel2019",
                  "alq.num.V1519","alq.pmq.V1519","alq.pm.V1519",
                  "tot_ann.V1519","ent.V1519","priv.V1519","shared.V1519","pmedio.V1519","pm_ent.V1519","pm_priv.V1519","pm_sha.V1519",
                  "RFD.2017",
                  "tot.comp.V1519","nou.comp.V1519","prot.comp.V1519","usat.comp.V1519","tot.eur.V1519","nou.eur.V1519","usat.eur.V1519","tot.eurm2.V1519","nou.eurm2.V1519","usat.eurm2.V1519"
                  )

Standardizar los datos

df <- scale(merged2)

Hier

d <- dist(df, method = "euclidean")

#ward hier
res.hc <- hclust(d, method = "ward.D2" )
#plot
plot(res.hc, cex = 0.6, hang = -1)

Cut 3

grp3 <- cutree(res.hc, k = 3)
table(grp3)
## grp3
##  1  2  3 
## 59  7  7
plot(res.hc, cex = 0.6)
rect.hclust(res.hc, k = 3, border = 2:5)

Cut 4

grp4 <- cutree(res.hc, k = 4)
table(grp4)
## grp4
##  1  2  3  4 
## 59  6  7  1
plot(res.hc, cex = 0.6)
rect.hclust(res.hc, k = 4, border = 2:5)

Cut 5

grp5 <- cutree(res.hc, k = 5)
table(grp5)
## grp5
##  1  2  3  4  5 
## 57  2  6  7  1
plot(res.hc, cex = 0.6)
rect.hclust(res.hc, k = 5, border = 2:5)