kmeans                  package:mva                  R Documentation

_K-_M_e_a_n_s _C_l_u_s_t_e_r_i_n_g

_D_e_s_c_r_i_p_t_i_o_n:

     Perform k-means clustering on a data matrix.

_U_s_a_g_e:

     kmeans(x, centers, iter.max = 10)

_A_r_g_u_m_e_n_t_s:

       x: A numeric matrix of data, or an object that can be coerced to
          such a matrix (such as a numeric vector or a data frame with
          all numeric columns). 

 centers: Either the number of clusters or a set of initial cluster
          centers. If the first, a random set of rows in `x' are chosen
          as the initial centers. 

iter.max: The maximum number of iterations allowed. 

_D_e_t_a_i_l_s:

     The data given by `x' is clustered by the k-means algorithm. When
     this terminates, all cluster centres are at the mean of their
     Voronoi sets (the set of data points which are nearest to the
     cluster centre).

     The algorithm of Hartigan and Wong (1979) is used.

_V_a_l_u_e:

     A list with components:

 cluster: A vector of integers indicating the cluster to which each
          point is allocated. 

 centers: A matrix of cluster centres.

withinss: The within-cluster sum of squares for each cluster.

    size: The number of points in each cluster.

_R_e_f_e_r_e_n_c_e_s:

     Hartigan, J.A. and Wong, M.A. (1979). A K-means clustering
     algorithm. Applied Statistics 28, 100-108.

_E_x_a_m_p_l_e_s:

     # a 2-dimensional example
     x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
                matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
     cl <- kmeans(x, 2, 20)
     plot(x, col = cl$cluster)
     points(cl$centers, col = 1:2, pch = 8)

