itemMatrix-class           package:arules           R Documentation

_C_l_a_s_s "_i_t_e_m_M_a_t_r_i_x" - _S_p_a_r_s_e _B_i_n_a_r_y _I_n_c_i_d_e_n_c_e _M_a_t_r_i_x _t_o _R_e_p_r_e_s_e_n_t _S_e_t_s
_o_f _I_t_e_m_s

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

     The 'itemMatrix' class is the basic building block for
     transactions, itemsets and rules in package 'arules'.  The class
     contains a sparse Matrix representation of items (a set of
     itemsets or transactions) and the corresponding item labels.

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s:

     Objects can be created by calls of the form 'new("itemMatrix",
     ...)'. However, most of the time objects will be created by
     coercion from a matrix, list or data.frame.

_S_l_o_t_s:

     '_d_a_t_a': Object of class 'ngCMatrix'  (from package 'Matrix') which
          stores  item occurrences in sparse representation.  Note that
          the  'ngCMatrix' is column-oriented and 'itemMatrix' is
          row-oriented with each row representing an element (an
          itemset, a transaction, etc.).  As a result, the 'ngCMatrix'
          in this slot is always a transposed version of the binary
          incidence matrix in 'itemMatrix'.

     '_i_t_e_m_I_n_f_o': a data.frame which contains named vectors of the
          length equal to the number of elements in the set.  If the
          slot is not empty (contains no item labels), the first
          element in the data.frame must have the name '"labels"' and
          contain a character vector with the item labels used for
          representing an item.  In addition to the item labels, the
          data.frame can contain arbitrary named vectors (of the same
          length) to represent, e.g., variable names and values which
          were used to create the binary items or hierarchical category
          information associated with each item label.  

     '_i_t_e_m_s_e_t_I_n_f_o': a data.frame which may contain additional 
          information for the rows (mostly representing itemsets) in
          the matrix. 

_M_e_t_h_o_d_s:

     _c_o_e_r_c_e 'signature(from = "matrix", to = "itemMatrix")'; expects
          'from' to be a binary matrix only containing 0s and 1s.

     _c_o_e_r_c_e 'signature(from = "list", to = "itemMatrix")'; 'from' is a
          list of vectors. Each vector contains one 
          set/transaction/....

     _c_o_e_r_c_e 'signature(from = "itemMatrix", to = "ngCMatrix")'; access
          the sparse matrix representation. Note, the 'ngCMatrix' 
          contains a transposed from of the itemMatrix.

     _c_o_e_r_c_e 'signature(from = "itemMatrix", to = "dgCMatrix")'; access
          the sparse matrix representation. Note, the 'dgCMatrix' 
          contains a transposed from of the itemMatrix.

     _c_o_e_r_c_e 'signature(from = "itemMatrix", to = "matrix")'; coerces to
          a dense 0-1 matrix of 'storage.mode' '"integer"' instead of 
          '"double"' to save memory.

     _c_o_e_r_c_e 'signature(from = "itemMatrix", to = "list")'; see also the
          methods for 'LIST'.

     _d_i_m 'signature(x = "itemMatrix")'; returns the dimensions of the
          itemMatrix.

     %_i_n% 'signature(x = "itemMatrix", table = "character")'; matches
          the strings in 'table' against the item labels  in 'x' and
          returns a logical vector indicating if a row (itemset) in 'x'
          contains _any_ of the items specified in 'table'. Note that
          there is a '%in%' method with  'signature(x = "itemMatrix",
          table = "character")'. This method is described in together
          with 'match'.

     %_a_i_n% 'signature(x = "itemMatrix", table = "character")';  matches
          the strings in 'table' against the item labels  in 'x' and
          returns a logical vector indicating if a row (itemset) in 'x'
          contains _all_ of the items specified in 'table'.

     %_p_i_n% 'signature(x = "itemMatrix", table = "character")';  matches
          the strings in 'table' against the item labels  in 'x' (using
          _partial_ matching) and returns a  logical vector indicating
          if a row (itemset) in 'x' contains _any_ of the items
          specified in 'table'.

     _i_t_e_m_L_a_b_e_l_s 'signature(object = "itemMatrix")'; returns the item
          labels used for encoding as a character vector.

     _i_t_e_m_L_a_b_e_l_s<- 'signature(object = "itemMatrix")'; replaces the item
          labels used for encoding.

     _i_t_e_m_I_n_f_o 'signature(object = "itemMatrix")'; returns the whole
          item/column information data.frame including labels.

     _i_t_e_m_I_n_f_o<- 'signature(object = "itemMatrix")'; replaces the
          item/column info by a data.frame.

     _i_t_e_m_s_e_t_I_n_f_o 'signature(object = "itemMatrix")'; returns the item
          set/row information data.frame.

     _i_t_e_m_s_e_t_I_n_f_o<- 'signature(object = "itemMatrix")'; replaces the
          item set/row info by a data.frame.

     _l_a_b_e_l_s 'signature(x = "transactions")'; returns the labels (item
          labels and element names)  for the matrix as a list of two
          vectors named 'items' and 'elements'. The following arguments
          can be used to customize the representation of the elements: 
          'itemSep',  'setStart' and  'setEnd'.

     _n_i_t_e_m_s 'signature(x = "itemMatrix")'; returns the number  of items
          (number in columns) in the itemMatrix.

     _s_h_o_w 'signature(object = "itemMatrix")'

     _s_u_m_m_a_r_y 'signature(object = "itemMatrix")'

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

     'LIST', 'c', 'duplicated', 'inspect', 'is.subset', 'is.superset',
     'itemFrequency', 'itemFrequencyPlot', 'match', 'length', 'sets',
     'subset', 'unique', '[-methods', 'image', 'ngCMatrix-class'  (from
     'Matrix'), 'transactions-class', 'itemsets-class', 'rules-class'

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

     ## Generate random data and coerce data to itemMatrix.
     m <- matrix(as.integer(runif(100000)>0.8), ncol=20)
     dimnames(m) <- list(NULL, paste("item", c(1:20), sep=""))
     i <- as(m, "itemMatrix")

     ## Get the number of elements (rows) in the itemMatrix.
     length(i)

     ## Get first 5 elements (rows) of the itemMatrix as list.
     as(i[1:5], "list")

     ## Get first 5 elements (rows) of the itemMatrix as matrix.
     as(i[1:5], "matrix")

     ## Get first 5 elements (rows) of the itemMatrix as sparse ngCMatrix.
     ## Warning: for efficiency reasons, the ngCMatrix you get is transposed!
     as(i[1:5], "ngCMatrix")

