[R] Using centers of hierarchical clustering for k-means

David L Carlson dcarlson at tamu.edu
Fri May 16 19:07:35 CEST 2014


This should get you started

> set.seed(42)
> x <- matrix(rnorm(200, 25, 5), 40, 5)
> x.clus <- hclust(dist(x))
> x.g4 <- cutree(x.clus, 4)
> x.cent <- aggregate(x, list(x.g4), mean)
> x.km <- kmeans(x, x.cent[,-1])
> xtabs(~x.g4+x.km$cluster)
    x.km$cluster
x.g4  1  2  3  4
   1 10  0  1  0
   2  0 12  2  0
   3  0  2 10  0
   4  0  0  0  3

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of marioger
Sent: Friday, May 16, 2014 7:29 AM
To: r-help at r-project.org
Subject: [R] Using centers of hierarchical clustering for k-means

Hi,

i have the following problem: I am using k-means algorithm for clustering.
But instead of using randomized centers, I would like to use centers created
by hierarchical clustering. So I want to apply "hclust" on my data set (in
this case the iris data), getting a solution by "cutree", calculating the
means/centers of the resulting clusters and use these centers as starting
points for k-means clusterng. But I have no idea how I calculate the centers
of the clusters and how to use them as starting points for the k-means
algorithm.

Hope you can help. Thanks in advance.

Mario



--
View this message in context: http://r.789695.n4.nabble.com/Using-centers-of-hierarchical-clustering-for-k-means-tp4690704.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list