R中的包Arules:在事务中添加了附加列

时间:2018-06-19 04:05:58

标签: r apriori arules

我有一个数据文件,记录事务的type,后跟事务中的项目(basket格式):

type1 | eggs | chocolate | milk
type2 | milk | bread
type1 | savory | tomato
type3 | chicken

我稍后想要删除带有外观的不同type值:

rules = apriori(dataset, parameter = list(support= 0.1, confidence=0.2), appearance = list(none = c("type=type1", "type=type2")

如何阅读type列的交易?以下内容不起作用,因为我有basket格式的数据。

dataset = read.transactions('data.csv', sep = '|', cols=c("type","Products"))

1 个答案:

答案 0 :(得分:1)

? read.transactions的手册页上显示:

  

...   cols:对于“单一”格式,“ cols”是数字或字符             长度为2的向量,给出了数字或名称             具有交易和项目ID的列(字段),             分别。如果是字符,则“文件”的第一行是             假定是带有列名的标题。对于“购物篮”             格式,“ cols”可以是数字标量,给出             具有交易ID的列(字段)。如果“ cols =             NULL”,则数据不包含交易ID。   ...

因此这应该适合您的数据:

dataset <- read.transactions('data.csv', sep = '|', cols=1)