[R] kmeans clustering

pingzhao pingzhao at waffle.cs.dal.ca
Mon Apr 14 05:53:21 CEST 2003


Hi,

I am using kmeans to cluster a dataset.
I test this example:

> data<-matrix(scan("data100.txt"),100,37,byrow=T)
(my dataset is 100 rows and 37 columns--clustering rows)

 > c1<-kmeans(data,3,20)
> c1
$cluster
  [1] 1 1 1 1 1 1 1 3 3 3 1 3 1 3 3 1 1 1 1 3 1 3 3 1 1 1 3 3 1 1 3 1 1 1 1 3 
3
 [38] 3 1 1 1 3 1 1 1 1 3 3 3 1 1 1 1 1 1 3 1 3 1 1 3 1 1 1 1 3 1 1 1 1 1 1 3 
1
 [75] 1 3 1 3 1 1 1 1 3 1 1 1 1 1 3 1 1 3 1 1 3 3 1 2 1 1

$withinss
[1] 1037.5987    0.0000  666.9701

$size
[1] 68  1 31

> c4<-kmeans(data,3,20)
$withinss
[1]   0.0000 865.7628 851.1214

$size
[1]  1 54 45

Does any one tell me why the results are very different with the same 
dataset and parameters when I run some times this command 
'kmeans(data,3,20)'???

Thank you for your help in advance!

ping



More information about the R-help mailing list