lookup                package:epicalc                R Documentation

_R_e_c_o_d_e _s_e_v_e_r_a_l _v_a_l_u_e_s _o_f _a _v_a_r_i_a_b_l_e

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

     Systematic replacement of several values of a variable using an
     array

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

     lookup(x, lookup.array) 

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

       x: a variable

lookup.array: a n-by-2 array used for looking up the recoding scheme

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

     This command is used for changing more than one value of a
     variable using a n-by-2 look-up array. The first column of the
     look-up array (index column) must be unique.

     If either the variable or the look-up table is character, the
     result vector will be character.

     For changing groups of factor variable, please use 'levels(var) <-
     ' instead.

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

     Virasakdi Chongsuvivatwong <cvirasak@medicine.psu.ac.th>

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

     'replace', 'recode'

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

     a       <- c( 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, NA)
     tx      <- rbind(c(1,2),c(2,1),c(3,4),c(4,NA),c(NA,3)) 

     # Swapping values of 1 and 2; rotating 3, 4 and NA
     new.a  <- lookup(a, tx)
     data.frame(a, new.a)
     tableA <- table(a, new.a, exclude=NULL) 
     # All non-diagonal cells which are non-zero are the recoded cells. 
     print(tableA, zero=".")

     ## Character look-up table
     b <- c(rep(letters[1:4],2), ".", NA)
     tx1 <- cbind(c(letters[1:5], ".", NA), c("Disease A","Disease B","Disease C", 
             "Disease D","Disease E", NA, "Unknown"))
     DiseaseName <- lookup(b, tx1)
     data.frame(b, DiseaseName)

