itemCoding              package:arules              R Documentation

_I_t_e_m _C_o_d_i_n_g - _H_a_n_d_l_i_n_g _I_t_e_m _L_a_b_e_l_s _a_n_d _C_o_l_u_m_n _I_D_s _C_o_n_v_e_r_s_i_o_n_s

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

     Provides the generic functions and the S4 methods for converting
     item labels into column IDs used in the binary matrix
     representation and vice versa.

     'decode' converts from the numeric (column IDs) representation to
     readable item labels.  'decode' is used by 'LIST'.

     'encode' converts from readable item labels to an itemMatrix using
     a given coding. With this method it is possible to create several
     compatible 'itemMatrix' objects (i.e., use the same binary
     representation for items) from data. 

     'recode' recodes an 'itemMatrix' object so its coding is
     compatible with another object.

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

     decode(x, ...)
     ## S4 method for signature 'list':
     decode(x, itemLabels)
     ## S4 method for signature 'numeric':
     decode(x, itemLabels)

     encode(x, ...)
     ## S4 method for signature 'list':
     encode(x, itemLabels, itemMatrix = TRUE)
     ## S4 method for signature 'character':
     encode(x, itemLabels, itemMatrix = TRUE)
     ## S4 method for signature 'numeric':
     encode(x, itemLabels, itemMatrix = TRUE)

     recode(x, ...)
     ## S4 method for signature 'itemMatrix':
     recode(x, itemLabels = NULL, match = NULL, ...)

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

       x: a vector or a list of vectors of character strings  (for
          'encode') or of numeric (for 'decode'), or an object of class
          'itemMatrix' (for 'recode').

itemLabels: a vector of character strings used for coding where  the
          position of an item label in the vector gives the item's
          column ID.   The used 'itemLabels' vector can be obtained
          from 'itemMatrix',   'transactions' and 'associations' by the
           method 'itemLabels'.

itemMatrix: return an object of class 'itemMatrix' otherwise an object
          of the same class as 'x' is returned.

   match: an 'itemMatrix' object whose item coding 'x'  should match.

     ...: further arguments.

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

     'recode' always returns an object of class 'itemMatrix'.

     For 'encode' with 'itemMatrix = TRUE' an object of class
     'itemMatrix' is returned. Otherwise the result is of the same type
     as 'x', e.g., a list or a vector.

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

     'LIST', 'associations-class', 'itemMatrix-class'

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

     data("Adult")

     ## Example 1: Manual decoding
     ## get code
     iLabels <- itemLabels(Adult)
     head(iLabels)

     ## get undecoded list and decode in a second step
     list <- LIST(Adult[1:5], decode = FALSE)
     list

     decode(list, itemLabels = iLabels)

     ## Example 2: Manually create an itemMatrix 
     data <- list(
         c("income=small", "age=Young"),
         c("income=large", "age=Middle-aged")
         )

     iM <- encode(data, iLabels)
     iM

     inspect(iM)

     ## use the itemMatrix to create transactions
     as(iM, "transactions")

     ## Example 3: use recode
     ## select first 100 transactions and all education-related items
     sub <- Adult[1:100, itemInfo(Adult)$variables ==  "education"]
     itemLabels(sub)
     image(sub)

     ## recode to match Adult again
     sub.recoded <- recode(sub, match = Adult)
     image(sub.recoded)

