1 #main function (choice between kmeans and hierarchical clustering)
2 getClusters = function(distances, method, K)
7 nstart = 10 #number of kmeans random restarts
8 maxiter = 100 #maximum iterations count in each km run
9 clusts = .Call("kmeansWithDistances", distances, K, nstart, maxiter)
11 else if (method=="HC")
13 #simple hierarchical clustering using ECT distances
14 hct = hclust(as.dist(distances),method="ward.D")
15 clusts = cutree(hct, K)
20 # renumbering step (post-processing after clustering)
21 reordering = function(clusts)
28 if (sum(clusts == i) > 0)
30 newCl[clusts == i] = counter