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

问题描述 投票:0回答:1

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

我的样本数据集:

ID  Item
1   Avas
2    Alo
2   Erbi
8   Abra
8    Ali
9    Inj
10  Avas
11  Avas
r arules
1个回答
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 
© www.soinside.com 2019 - 2024. All rights reserved.