[R] k- means cluster analysis
Ngayee J Law
Ngayee.Law at celeradiagnostics.com
Thu Feb 13 02:13:02 CET 2003
Hi all,
I am trying to run the k-means cluster analysis using the function kmeans
in the package cluster.
The data are:
x = c(-0.26, -0.23, -0.05, -0.20, 0.30, -0.84, -0.10, -0.12, 0.10, -0.31,
-0.19, 0.18, -0.26,
-0.23, -0.37, -0.23)
I've got two different solutions when I ran this function over a few times:
kmeans(x, centers=2)
The first solution gives the following:
$cluster
[1] 2 2 1 2 1 2 2 2 1 2 2 1 2 2 2 2
$centers
[,1]
1 0.1325000
2 -0.2783333
$withinss
[1] 0.0646750 0.4033667
$size
[1] 4 12
The second solution gives the following:
$cluster
[1] 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1
$centers
[,1]
1 -0.1313333
2 -0.8400000
$withinss
[1] 0.5035733 0.0000000
$size
[1] 15 1
I don't understand why this is happening, and how do I choose between the
two solutions. Also, how can I ensure
consistent solution over times? Thanks a lot!
- Jacqueline
More information about the R-help
mailing list