class.ind                package:nnet                R Documentation

_G_e_n_e_r_a_t_e_s _C_l_a_s_s _I_n_d_i_c_a_t_o_r _M_a_t_r_i_x _f_r_o_m _a _F_a_c_t_o_r

_D_e_s_c_r_i_p_t_i_o_n:

     Generates a class indicator function from a given factor.

_U_s_a_g_e:

     class.ind(cl)

_A_r_g_u_m_e_n_t_s:

      cl: factor or vector of classes for cases. 

_V_a_l_u_e:

     a matrix which is zero except for the column corresponding to the
     class.

_R_e_f_e_r_e_n_c_e_s:

     Venables, W. N. and Ripley, B. D. (2002) _Modern Applied
     Statistics with S._ Fourth edition.  Springer.

_E_x_a_m_p_l_e_s:

     # The function is currently defined as
     class.ind <- function(cl)
     {
       n <- length(cl)
       cl <- as.factor(cl)
       x <- matrix(0, n, length(levels(cl)) )
       x[(1:n) + n*(unclass(cl)-1)] <- 1
       dimnames(x) <- list(names(cl), levels(cl))
       x
     }

