[R] Kmeans again

Luis Miguel Almeida da Silva lsilva at fc.up.pt
Fri Jun 6 12:15:48 CEST 2003


Dear helpers
 
I'm sorry to insist but I still think there is something wrong with the function kmeans. For instance, let's try the same small example:
 
> dados<-matrix(c(-1,0,2,2.5,7,9,0,3,0,6,1,4),6,2)

I will choose observations 3 and 4 for initial centers and just one iteration. The results are
 
> A<-kmeans(dados,dados[c(3,4),],1)
> A
$cluster
[1] 1 1 1 1 2 2
$centers
   [,1] [,2]
1 0.875 2.75
2 8.000 2.50
$withinss
[1] 38.9375  6.5000
$size
[1] 4 2
 
If I do it by hand, after one iteration, the results are
 
$cluster
[1] 1 2 1 2 1 2
 
So I think that something is wrong with the function kmeans; probably the initial centers given by the user are not being taken into account.




More information about the R-help mailing list