codes-deprecated            package:base            R Documentation

_F_a_c_t_o_r _C_o_d_e_s

_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.

     It is now 'Deprecated'.

_U_s_a_g_e:

     codes(x, ...)
     codes(x, ...) <- value

_A_r_g_u_m_e_n_t_s:

       x: an object from which to extract or set the codes.

     ...: further arguments passed to or from other methods.

   value: replacement value.

_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 ordering 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.
     *Warning:* the sort order may well depend on the locale, and
     should not be assumed to be ASCII.

_N_o_t_e:

     Normally 'codes' is not the appropriate function to use with an
     unordered factor.  Use 'unclass' or 'as.numeric' to extract the
     codes used in the internal representation of the factor, as these
     do not assume that the codes are sorted.

     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:

     'factor', 'levels', 'nlevels'.

_E_x_a_m_p_l_e_s:

     ## Not run: 
     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!
     ## End(Not run)

