R: I did a cluster analysis - how do I add group classification to my source data?

Suppose I have 4 variables (x, y, z, r) and 10 obs. I run cluster analysis in R and get 2 clusters that fit. Now I want these clusters to match the data. Thus, the table will look like this:

Respondent x,y,z,r cluster 1 2 3 . . 10 

Can someone please tell me the code to get this table. The code I used for cluster analysis is as follows:

 ##Scaling cluster1=scale(cluster) ###Hierarchial Cluster cluster1=dist(cluster,method="euclidean") summary(cluster1) cluster2=hclust(cluster1,method="ward") plot(cluster2) 

Thanks A

+4
source share
1 answer

Using your data, assuming the cluster of objects contains the source variables x, y, z, and r in the columns:

 groups = cutree(cluster2, 2) result = cbind(cluster, groups) 
+6
source

Source: https://habr.com/ru/post/1347149/


All Articles