I am currently using the arules package to perform a market basket analysis. My data that I read in looks like this (but with many more rows):
>data
transaction_id item
1 1 beer
2 1 beer
3 1 soda
4 2 beer
5 3 beer
6 3 fries
7 3 candy
8 4 soda
9 4 fries
I then transform it using dcast and remove the transaction id column:
> Trans_Table <- dcast(data, transaction_id ~ item)
> Trans_Table$transaction_id <- NULL
and it looks like this:
beer candy fries soda
1 2 0 0 1
2 1 0 0 0
3 1 1 1 0
4 0 0 1 1
but then when I make it into the "transactions" class so I can use the apriori function, it converts the 2 under beer to a 1
> Transactions <- as(as.matrix(Trans_Table), "transactions")
Warning message:
In asMethod(object) :
matrix contains values other than 0 and 1! Setting all entries != 0 to 1.
Is there any way to perform the market basket analysis and maintain that 2? In other words, I would like to see rules for {beer} => {beer}, {beer, beer} => {soda}, and {beer, soda} => {beer} but it is currently only counting beer once per each transaction even if it was purchased twice.
Can anyone help out with this?