itemMatrix-class {arules} | R Documentation |
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.
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
.
data
:dgCMatrix
(from package Matrix) which stores
item occurrences in sparse representation. Note that the
dgCMatrix
is column-oriented and itemMatrix
is
row-oriented with each row representing an element (an itemset, a
transaction, etc.). As a result, the dgCMatrix
in this
slot is always a transposed version of the binary incidence matrix
in itemMatrix
.
itemInfo
:"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.
signature(from = "matrix", to = "itemMatrix")
signature(from = "list", to = "itemMatrix")
signature(from = "itemMatrix", to = "dgCMatrix")
dgCMatrix
contains a transposed from of the itemMatrix.
signature(from = "itemMatrix", to = "matrix")
signature(from = "itemMatrix", to = "list")
signature(x = "itemMatrix")
;
returns the dimensions of the itemMatrix.signature(x = "itemMatrix")
: matches values
against the item labels for
each element (row) in the itemMatrix.signature(x = "itemMatrix")
: matches values
against the item labels for
each element (row) in the itemMatrix using partial matching.signature(object = "itemMatrix")
;
returns the item labels used for encoding as a character vector.signature(object = "itemMatrix")
;
replaces the item labels used for encoding.signature(object = "itemMatrix")
;
returns the whole item information data.frame
including
labels.signature(object = "itemMatrix")
;
replaces the item info by a data.frame
.
The length of the vectors in the data.frame
has to match
the number of elements (rows) in the itemMatrix.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
.
signature(object = "itemMatrix")
signature(object = "itemMatrix")
dgCMatrix-class
(from Matrix),
transactions-class
,
itemsets-class
,
rules-class
## 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 dgCMatrix. ## Warning: for efficiency reasons, the dgCMatrix you get is transposed! as(i[1:5], "dgCMatrix")