dropUnusedLevels            package:Hmisc            R Documentation

_C_r_e_a_t_e _T_e_m_p_o_r_a_r_y _F_a_c_t_o_r _S_u_b_s_e_t_t_i_n_g _F_u_n_c_t_i_o_n

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

     Calling this function makes Hmisc have its pre-version 3.0
     behavior in which the R '[.factor' function was overridden by a
     customized version that caused unused 'factor' 'level's to be
     dropped when the factor variable was subscripted (subsetted).
     'dropUnusedLevels()' creates a temporary version of '[.factor' in
     the global environment, which will take precedence.  To later make
     this function keep unused levels on subsetting, issue
     'options(drop.unused.levels=FALSE)' or just remove this temporary
     function from the environment by issuing
     'remove('[.factor',pos='.GlobalEnv')'.

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

     dropUnusedLevels()

_A_u_t_h_o_r(_s):

     Frank Harrell and Jens Oehlschlaegel

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

     'factor','[.factor'

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

     ## Not run: 
     x <- factor(c('a','b','c'))
     x[1:2]  # keeps level c
     dropUnusedLevels()
     x[1:2]  # no c any more
     ## End(Not run)

