2

I used k-means cluster algorithm on a data-frame df1 and the result is shown in the 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 Is there a possibility to add to the data frame information from which cluster does the observation come from?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Michał
  • 273
  • 1
  • 3
  • 13

1 Answers1

6

You already have the information you want:

kmeansRes<-factor(km$cluster)

just add it to your data frame as additional column.

df1$cluster <- km$cluster
Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194