Mr.NoName Mr.NoName - 1 month ago 11
R Question

How to use ARules package on a CSV file?

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.

Answer

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))
Comments