set.seed(1234)
## 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")
## create itemsets from itemMatrix
is <- new("itemsets", items = i[1:3])
inspect(is)
## create rules (rhs and lhs cannot share items so I use
## itemSetdiff here)
rules <- new("rules", lhs=itemSetdiff(i[4:6],i[1:3]), rhs=i[1:3])
inspect(rules)
##
Run the code above in your browser using DataLab