gl                   package:base                   R Documentation

_G_e_n_e_r_a_t_e _F_a_c_t_o_r _L_e_v_e_l_s

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

     Generate factors by specifying the pattern of their levels.

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

     gl(n, k, length = n*k, labels = 1:n, ordered = FALSE)

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

       n: an integer giving the number of levels.

       k: an integer giving the number of replications.

  length: an integer giving the length of the result.

  labels: an optional vector of labels for the resulting factor levels.

 ordered: a logical indicating whether the result should be ordered or
          not.

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

     The result has levels from '1' to 'n' with each value replicated
     in groups of length 'k' out to a total length of 'length'.

     'gl' is modelled on the _GLIM_ function of the same name.

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

     The underlying 'factor()'.

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

     ## First control, then treatment:
     gl(2, 8, labels = c("Control", "Treat"))
     ## 20 alternating 1s and 2s
     gl(2, 1, 20)
     ## alternating pairs of 1s and 2s
     gl(2, 2, 20)

