Learn R Programming

arules (version 0.2-6)

transactions-class: Class ``transactions'' --- Binary Incidence Matrix for Transactions

Description

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.

Arguments

Objects from the Class

Objects are created by coercion from objects of other classes or by calls of the form new("transactions", ...).

Extends

Class itemMatrix, directly.

See Also

itemMatrix-class

Examples

Run this code
### 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)

Run the code above in your browser using DataLab