r - Assign class to data frame after clustering -


i used k-means cluster algorithm on data-frame df1 , result shown in picture below.

library(ade4) df1 <- data.frame(x=runif(100), y=runif(100)) plot(df1) km <- kmeans(df1, centers=3) kmeansres<-factor(km$cluster) s.class(df1,fac=kmeansres, add.plot=true, col=rainbow(nlevels(kmeansres))) 

enter image description here there possibility add data frame information cluster observation come from?

you have information want:

kmeansres<-factor(km$cluster) 

just add data frame additional column.

df1$cluster <- km$cluster 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -