How to prep transaction data into basket for arules

若如初见. 提交于 2019-11-27 22:27:21

Take a look at the help page for the "transactions" data type for examples on how to get your data in:

library(arules)
?transactions

For your type, you want to split by Order, then use as to get it into a transactions list:

trans <- as(split(data[,"Part"], data[,"Order"]), "transactions")
inspect(trans)
  items     transactionID
1 {A,B,G}   1            
2 {R}       2            
3 {A,B}     3            
4 {E}       4            
5 {Y}       5            
6 {A,B,F,V} 6   

I've had a lot of trouble with coercion (e.g., 'as(dataname, "transactions"..).

I believe that this is due to the fact that I have duplicate records (i.e., the same item purchased more than once in the same transation, when the data is in 'single' format).

This is what finally worked for me:

Transactions<- read.transactions("Data with tx ids, item names, in
                      single format.csv", 
                      rm.duplicates= TRUE, sep=",",
                      format = "single", cols = c(7,9));

(tx id in column 7, item names in column 9)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!