为常规格式转换为arules包的稀疏格式

时间:2015-03-07 08:31:06

标签: r arules

我正在尝试将常规数据集转换为稀疏格式。所有文档都有“稀疏格式”的例子你能帮帮我吗?

我的样本数据集:

ID  Item
1   Avas
2    Alo
2   Erbi
8   Abra
8    Ali
9    Inj
10  Avas
11  Avas

1 个答案:

答案 0 :(得分:0)

转换为事务类:

trans1 <- as(split(df1[,"Item"], df1[,"ID"]), "transactions")

结果:

summary(trans1)
# transactions as itemMatrix in sparse format with
# 6 rows (elements/itemsets/transactions) and
# 6 columns (items) and a density of 0.2222222 
# 
# most frequent items:
#   Avas    Abra     Ali     Alo    Erbi (Other) 
#      3       1       1       1       1       1