divideUp               package:hddplot               R Documentation

_P_a_r_t_i_t_i_o_n _d_a_t_a _i_n_t_o _m_u_t_i_p_l_e _n_e_a_r_l_y _e_q_u_a_l _s_u_b_s_e_t_s

_D_e_s_c_r_i_p_t_i_o_n:

     Randomly partition data into nearly equal subsets. If
     'balanced=TRUE' the requirement is imposed that the subsets should
     as far as possible be balanced with respect to a classifying
     factor.  The multiple sets are suitable for use for determining
     the folds in a cross-validation.

_U_s_a_g_e:

     divideUp(cl, nset = 2, seed = NULL, balanced=TRUE)

_A_r_g_u_m_e_n_t_s:

      cl: classifying factor

    nset: number of subsets into which to partition data

    seed: set the seed, if required, in order to obtain reproducible
          results

balanced: logical: should subsets be as far as possible balanced with
          respect to the classifying factor?

_D_e_t_a_i_l_s:

_V_a_l_u_e:

     a set of indices that identify the 'nset' subsets

_N_o_t_e:

_A_u_t_h_o_r(_s):

     John Maindonald

_R_e_f_e_r_e_n_c_e_s:

_S_e_e _A_l_s_o:

     ~~objects to See Also as 'help', ~~~

_E_x_a_m_p_l_e_s:

     foldid <- divideUp(cl=rep(1:3, c(17,14,8)), nset=10)
     table(rep(1:3, c(17,14,8)), foldid)
     foldid <- divideUp(cl=rep(1:3, c(17,14,8)), nset=10,
                 balanced=FALSE)
     table(rep(1:3, c(17,14,8)), foldid)

     ## The function is currently defined as
     function(cl = rep(1:3, c(7, 4, 8)), nset=2, seed=NULL, balanced=TRUE){
         if(!is.null(seed))set.seed(seed)
         if(balanced){
           ord <- order(cl)
           ordcl <- cl[ord]
           gp0 <- rep(sample(1:nset), length.out=length(cl))
           gp <- unlist(split(gp0,ordcl), function(x)sample(x))
           gp[ord] <- gp
         } else
         gp <- sample(rep(1:nset, length.out=length(cl)))
         as.vector(gp)
       }

