recode                  package:car                  R Documentation

_R_e_c_o_d_e _a _V_a_r_i_a_b_l_e

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

     Recodes a numeric vector, character vector, or factor  according
     to simple recode specifications.

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

     recode(var, recodes, as.factor.result)

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

     var: numeric vector, character vector, or factor.

 recodes: character string of recode specifications: see below.

as.factor.result: return a factor; default is 'TRUE' if  'var' is a
          factor, 'FALSE' otherwise.

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

     Recode specifications appear in a character string, separated by
     semicolons (see the examples below), of the form 'input=output'.
     If an input value satisfies more than one specification,  then the
     first (from left to right) applies. If no specification is
     satisfied, then the input value is carried over to the result.
     'NA' is allowed on input and output. Several recode specifications
     are supported:

     _s_i_n_g_l_e _v_a_l_u_e For example, '0=NA'.

     _v_e_c_t_o_r _o_f _v_a_l_u_e_s For example, 'c(7,8,9)='high''.

     _r_a_n_g_e _o_f _v_a_l_u_e_s For example, '7:9='C''. The special values 'lo'
          and 'hi' may appear in a range. For example, 'lo:10=1'.

     '_e_l_s_e' everything that does not fit a previous specification. For
          example, 'else=NA'. Note that 'else' matches _all_ otherwise
          unspecified values on input, including 'NA'.

     If all of the output values are numeric, and if 'as.factor.result'
     is  'FALSE', then a numeric result is returned.

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

     a recoded vector of the same length as 'var'; if 'va'r is a
     factor, then so is the result.

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

     John Fox jfox@mcmaster.ca

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

     'cut', 'factor'

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

     x<-rep(1:3,3)
     x
     ## [1] 1 2 3 1 2 3 1 2 3
     recode(x, "c(1,2)='A'; else='B'")
     ## [1] "A" "A" "B" "A" "A" "B" "A" "A" "B"
     recode(x, "1:2='A'; 3='B'")
     ## [1] "A" "A" "B" "A" "A" "B" "A" "A" "B"

