require(cluster)
t1 = Sys.time()
# A subset of the Ruspini data set from the package "cluster""
x = as.matrix(ruspini)[51:75,]
# assign random weights to observations
w = sample(1:20,nrow(x),replace = TRUE)
# hierarchical clustering with observational weights
h = Whclust(x,w)
#print the hclust object
print(h)
#plot the hierarchical tree
plot(h)
#cut the hierarchical tree to get 2 clusters
k2 = cutree(h,2)
table(k2)
#plot the clustering result
plot(x,cex = log(w),pch = 16,col = k2)
t2 = Sys.time()
Run the code above in your browser using DataLab