

_F_a_c_t_o_r _C_o_d_e_s

     codes(x)
     codes(x) <- value

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

     This (generic) function returns a numeric coding of a
     factor. It can also be used to assign to a factor using
     the coded form.

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

     For an ordered factor, it returns the internal coding
     (1 for the lowest group, 2 for the second lowest,
     etc.). For an unordered factor, an alphabetical order-
     ing of the levels is assumed, i.e the level that is
     coded 1 is the one whose name is sorted first according
     to the prevailing collating sequence.

_N_o_t_e:

     The behaviour for unordered factors is dubious, but
     compatible with S version 3. To get the internal coding
     of a factor, use `as.integer'. Note in particular that
     the codes may not be the same in different language
     locales because of collating differences.

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

     `unclass' is very similar if applied to factors; `fac-
     tor', `levels', `nlevels'.

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

     codes(rep(factor(c(20,10)),3))

     x <- gl(3,5)
     codes(x)[3] <- 2
     x

     data(esoph)
     ( ag <- esoph$alcgp[12:1] )
     codes(ag)

     codes(factor(1:10)) # BEWARE!

