transactions-class {arules} | R Documentation |
The transactions
class represents transaction data used for
mining itemsets or rules. It is a direct extension of class
itemMatrix
to store a binary incidence
matrix, item labels, and optionally transaction IDs and user IDs.
Objects are created by coercion from objects of other classes or by
calls of the form new("transactions", ...)
.
transactionInfo
:"data.frame"
with vectors of the same length as the number of
transactions. Each vector can hold additional information, e.g.,
store transaction IDs or user IDs for each transaction.data
:dgCMatrix
to store the
binary incidence matrix (see
itemMatrix
class)itemInfo
:"data.frame"
to store
item labels (see itemMatrix
class)
Class itemMatrix
, directly.
signature(from = "matrix", to = "transactions")
;
produces a transactions data set from a binary incidence matrix.
The row names are used as item labels and the column names are
stores as transaction IDs.
signature(from = "list", to = "transactions")
;
produces a transactions data set from a list. The names of the
items in the list are used as item labels and the item IDs and the
incidence matrix is produced automatically.
signature(from = "transactions", to = "matrix")
signature(from = "transactions", to = "list")
signature(from = "data.frame", to = "transactions")
;
recodes the data frame containing only categorical variables (all
have to be factors) into a binary transaction data set. The needed
number of dummy items are automatically generated. The item
labels are generated by concatenating variable names and levels with
a "=".
The variable names and levels are stored in the labels data frame
as the components variables
and levels
.signature(from = "transactions", to = "data.frame")
;
represents the set of transactions in a printable form
as a data.frame
.
Note that this does not reverse coercion from data.frame
to transactions
.signature(x = "transactions")
;
returns the labels (item labels and transaction IDs)
for the incidence matrix as a list of two vectors named items
and transactionID
.signature(x = "transactions")
;
replaces the transactionInfo data framesignature(x = "transactions")
;
returns transactionInfosignature(object = "transactions")
signature(object = "transactions")
[-methods
,
LIST
,
WRITE
,
c
,
image
,
inspect
,
read.transactions
,
random.transactions
,
sets
,
itemMatrix-class
### 1. example: creating transactions form a list a_list <- list( c("a","b","c"), c("a","b"), c("a","b","d"), c("c","e"), c("a","b","d","e"), ) # set transaction names names(a_list) <- paste("Tr",c(1:5), sep = "") a_list # coerce into transactions trans <- as(a_list, "transactions") # analyze transactions summary(trans) image(trans) ### 2. example: creating transactions from a matrix a_matrix <- matrix( c(1,1,1,0,0, 1,1,0,0,0, 1,1,0,1,0, 0,0,1,0,1, 1,1,0,1,1), ncol = 5) # set dim names dimnames(a_matrix) <- list( c("a","b","c","d","e"), paste("Tr",c(1:5), sep = "")) a_matrix # coerce trans2 <- as(a_matrix, "transactions") trans2 ### example 3: creatring transactions from data.frame a_data.frame <- data.frame( age = as.factor(c(6,8,7,6,9,5)), grade = as.factor(c(1,3,1,1,4,1))) # note: all attributes have to be factors a_data.frame # coerce trans3 <- as(a_data.frame, "transactions") image(trans3)