cutree                 package:stats                 R Documentation

_C_u_t _a _t_r_e_e _i_n_t_o _g_r_o_u_p_s _o_f _d_a_t_a

_D_e_s_c_r_i_p_t_i_o_n:

     Cuts a tree, e.g., as resulting from 'hclust', into several groups
     either by specifying the desired number(s) of groups or the cut
     height(s).

_U_s_a_g_e:

     cutree(tree, k = NULL, h = NULL)

_A_r_g_u_m_e_n_t_s:

    tree: a tree as produced by 'hclust'. 'cutree()' only expects a
          list with components 'merge', 'height', and 'labels', of
          appropriate content each.

       k: an integer scalar or vector with the desired number of groups

       h: numeric scalar or vector with heights where the tree should
          be cut.

     At least one of 'k' or 'h' must be specified, 'k' overrides 'h' if
     both are given.

_V_a_l_u_e:

     'cutree' returns a vector with group memberships if 'k' or 'h' are
     scalar, otherwise a matrix with group meberships is returned where
     each column corresponds to the elements of 'k' or 'h',
     respectively (which are also used as column names).

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

_S_e_e _A_l_s_o:

     'hclust', 'dendrogram' for cutting trees themselves.

_E_x_a_m_p_l_e_s:

     data(USArrests)

     hc <- hclust(dist(USArrests))

     cutree(hc, k=1:5)#k = 1 is trivial
     cutree(hc, h=250)

     ## Compare the 2 and 3 grouping:
     g24 <- cutree(hc, k = c(2,4))
     table(g24[,"2"], g24[,"4"])

