cut2                  package:Hmisc                  R Documentation

_C_u_t _a _N_u_m_e_r_i_c _V_a_r_i_a_b_l_e _i_n_t_o _I_n_t_e_r_v_a_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Function like cut but left endpoints are inclusive and labels are
     of the form '[lower, upper)', except that last interval is
     '[lower,upper]'.   If cuts are given, will by default make sure
     that cuts include entire range of 'x'. Also, if cuts are not
     given, will cut 'x' into quantile groups  ('g' given) or groups
     with a given minimum number of observations ('m').  Whereas cut
     creates a category object, 'cut2' creates a factor object.

_U_s_a_g_e:

     cut2(x, cuts, m, g, levels.mean, digits, minmax=TRUE, oneval=TRUE)

_A_r_g_u_m_e_n_t_s:

       x: numeric vector to classify into intervals 

    cuts: cut points 

       m: desired minimum number of observations in a group 

       g: number of quantile groups 

levels.mean: set to 'TRUE' to make the new categorical vector have
          levels attribute that is the group means of 'x' instead of
          interval endpoint labels 

  digits: number of significant digits to use in constructing levels. 
          Default is 3 (5 if 'levels.mean=TRUE') 

  minmax: if cuts is specified but 'min(x)<min(cuts)' or
          'max(x)>max(cuts)', augments cuts to include min and max 'x' 

  oneval: if an interval contains only one unique value, the interval
          will be labeled with the formatted version of that value
          instead of the interval endpoints, unless 'oneval=FALSE' 

_V_a_l_u_e:

     a factor variable with levels of the form '[a,b)' or formatted
     means (character strings)

_S_e_e _A_l_s_o:

     'cut', 'quantile'

_E_x_a_m_p_l_e_s:

     set.seed(1)
     x <- runif(1000, 0, 100)
     z <- cut2(x, c(10,20,30))
     table(z)
     table(cut2(x, g=10))      # quantile groups
     table(cut2(x, m=50))      # group x into intevals with at least 50 obs.

