---
# System prepended metadata

title: TD clustring - code
tags: [Ensai - public]

---

---
tags: Ensai - public
---

# TD clustring - code

```
anciennete=c(2,3,5,6,8)
salaire=c(2000,2100,3500,4100,10000)

data=cbind(anciennete,salaire)
data=as.data.frame(data)
dataScale=as.data.frame(scale(data))

distance= function(i,j,data) {
    sqrt(
    rowSums((data[i,]-data[j,])**2 )
    )
}

distances= function(data){
    a= matrix(data = rep(0, 25), nrow = 5, ncol = 5)
    for (i in 1:5) {
         for (j in i:5) {
            a[i,j]=distance(i,j,data)
        }
    }
    round(a,2)
}

distances(data)
distances(dataScale)


library(FactoMineR)
library(Factoshiny)
library(explor)

# install.packages("Factoshiny")
# install.packages("explor")

Factoshiny::HCPCshiny(data) 

Factoshiny::PCAshiny(data)

res.PCA<-PCA(data,ncp=Inf, scale.unit=TRUE,graph=FALSE)
res.HCPC=HCPC(res.PCA,method="single")
explor(res.PCA)

```