2016-12-20 79 views
0

我正在玩市場購物籃可視化。使用下面的代碼,我得到一個數據集,我可以使用它進行一些很好的可視化。如何創建您自己的「交易」數據集以用於市場購物籃分析的可視化

library("arules") 
library("arulesViz") 

data("Groceries") 
summary(Groceries) 

這一切工作正常,但事情是,我想調整一些數據。

我看到的數據是這樣定義的:

class(Groceries) 
[1] "transactions" 
attr(,"package") 
[1] "arules" 

我如何能創建自己的數據集這樣的任何想法?

回答

1

引述幫助文件?arules::transactions,這裏有一個方法:

library(arules) 

## example 1: 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 
trans1 <- as(a_list, "transactions") 
trans1 
# transactions in sparse format with 
# 5 transactions (rows) and 
# 5 items (columns)