r - How to convert a csv data in to a market basket format? -


i have data in following format:

txnid    items     1            1        b     1        c     2        r      2        t 

where "txnid" , "items" columns. imported file in r , ran following commands:

df_fact <- data.frame(lapply(mydata,as.factor)) df_trans <- as(df_fact, 'transactions') 

when run apriori command throws error.

rules = apriori(df_trans, parameter=list(supp=0.95, conf=0.95, target=”rules”)) inspect(rules) #null inspect(rules[1:5]) error in inspect(rules[1:5]) :    error in evaluating argument 'x' in selecting method function 'inspect': error in slot(x, s)[i] : subscript out of bounds 

also let me know in format r accepts data.

it should work this:

mydata <- read.table(header = true, text = " txnid    items 1        1        b 1        c 2         2        b ") library(arules) df_trans <- as(split(mydata$items, mydata$txnid), "transactions") rules <- apriori(df_trans, parameter=list(supp=0.95, conf=0.95, target="rules")) inspect(rules) #   lhs    rhs support confidence lift # 1 {}  => {a}       1          1    1 # 2 {}  => {b}       1          1    1 # 3 {a} => {b}       1          1    1 # 4 {b} => {a}       1          1    1 

you may need loosen supp and/or conf find rules in data set.


Comments