1

I have the following example data

Timestamp,Col1,Col2,Col3,Col4,Col5
2/11/2016 22:59:24,1,1,1,0,0
2/12/2016 14:43:01,0,0,0,0,0
2/12/2016 15:19:37,1,1,1,1,0
2/13/2016 17:33:38,1,1,1,0,1
2/14/2016 15:59:31,1,1,1,1,0

I have imported this as a data object in R.

I want to use the arules library to analyze this.

But so far, I have only been able to execute the following code:

require(arules)
data(package="arules")
data(Groceries)
Groceries
summary(Groceries)
itemFrequencyPlot(Groceries,topN=20,type="absolute")
rules <- apriori(Groceries, parameter = list(supp = 0.0001, conf = 0.8))

I don't understand why the functions don't work on my data object.

MY QUESTION

Can some explain how I can get these functions to work on my CSV data? I think it's simply a matter of formatting it correctly with the right function, but I'm not sure how to do that.

Community
  • 1
  • 1
Mr.NoName
  • 125
  • 4
  • 13
  • did you convert your data to `transactions`? e.g. with `read.transactoins`, see http://stackoverflow.com/questions/17313450/how-to-convert-data-frame-to-transactions-for-arules – Bulat Oct 30 '16 at 19:06
  • I attempted to do this. `trans = read.transactions(MyData,format = "basket")` but this didn't work. I'm sure I'm Implementing it wrong. – Mr.NoName Oct 30 '16 at 19:09

1 Answers1

2

You can do

MyData <- read.csv(text="Timestamp,Col1,Col2,Col3,Col4,Col5
2/11/2016 22:59:24,1,1,1,0,0
2/12/2016 14:43:01,0,0,0,0,0
2/12/2016 15:19:37,1,1,1,1,0
2/13/2016 17:33:38,1,1,1,0,1
2/14/2016 15:59:31,1,1,1,1,0")
require(arules)
trans <- as(MyData[,-1]>0, "transactions") 
rules <- apriori(trans, parameter = list(supp = 0.0001, conf = 0.8))
lukeA
  • 53,097
  • 5
  • 97
  • 100