relabel                package:memisc                R Documentation

_C_h_a_n_g_e _l_a_b_e_l_s _o_f _f_a_c_t_o_r_s _o_r _l_a_b_e_l_l_e_d _o_b_j_e_c_t_s

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

     Function 'relabel' changes the labels of a factor or any object
     that has a 'names', 'labels', 'value.labels', or 'variable.labels'
     attribute. Function 'relabel4' is an (internal) generic which is
     called by 'relabel' to handle S4 objects.

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

     ## Default S3 method:
     relabel(x, ..., gsub = FALSE, fixed = TRUE, warn = TRUE)
     ## S3 method for class 'factor':
     relabel(x, ..., gsub = FALSE, fixed = TRUE, warn = TRUE)

     ## S4 method for signature 'item':
     relabel4(x, ...)
     # This is an internal method, see details.
     # Use relabel(x, ...) for 'item' objects

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

       x: An object with a 'names', 'labels', 'value.labels', or
          'variable.labels' attribute

     ...: A sequence of named arguments, all of type character

    gsub: a logical value; if TRUE, 'gsub' is used to change the labels
          of the object. That is, instead of substituting whole labels,
          substrings of the labels of the object can changed.

   fixed: a logical value, passed to 'gsub'. If TRUE, substitutions are
          by fixed strings and not by regular expressions.

    warn: a logical value; if TRUE, a warning is issues if a a change
          of labels was unsuccessful.

_D_e_t_a_i_l_s:

     This function changes the names or labels of 'x' according to the
     remaining arguments. If 'gsub' is FALSE, argument tags are the
     _old_ labels, the values are the new labels. If 'gsub' is TRUE,
     arguments are substrings of the labels that are substituted by the
     argument values.

     Function 'relabel' is S3 generic. If its first argument is an S4
     object, it calls the (internal) 'relabel4' generic function.

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

     The object 'x' with new labels defined by the ... arguments.

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

       f <- as.factor(rep(letters[1:4],5))
       levels(f)
       F <- relabel(f,
         a="A",
         b="B",
         c="C",
         d="D"
         )
       levels(F)
       
       f <- as.item(f)
       labels(f)
       F <- relabel(f,
         a="A",
         b="B",
         c="C",
         d="D"
         )
       labels(F)

