dat <- rbind(matrix(rnorm(100, mean = 0, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2))
res <- KmeansQuick(dat, K=3)
plot(dat[,1], dat[,2], type = "p", xlab = "x", ylab = "y",
col = res$cluster, main = "K-means clustering")
Run the code above in your browser using DataLab