I'm using the arules
package in R
to extract some association rules and want to filter by the length of the left hand side (lhs).
I tried using subset but without success.
This is my mode and attempt:
trans<-read.transactions(file='file.csv', format="single", sep=",",cols=c("userid","target"))
inspect(head(trans,3))
rules<-apriori(trans,parameter=list(support=0.06, confidence=0.5,minlen=3,maxlen=6))
# sort by support
top.support <- sort(rules, decreasing = TRUE, na.last = NA, by = "support")
This is what I'm doing:
subset(rules,subset=length(lhs)==5) # not working. it return set of 0 rules
Any suggestions?
length
gives you the number of rules. You need to use size
instead.
subset(rules,subset = size(lhs) == 5)