Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R arules - subset of transactions that match a rule

Tags:

r

subset

arules

I'm using the R package arules. I have some transactions and a rule (see below). I want the subset of transactions that break the rule. How can I do that?

This is the set up:

library(arules)
data(Adult)
summary(Adult)
rules = apriori(Adult,parameter=list(support=0.2,confidence=0.8))
summary(rules)
r=rules[1]

I want the subset of transactions that contain the left hand side of the rule r but not the right hand side. The arules documentation doesn't have an example like this. I've tried %in%, match and subset but I can't get the syntax right.

The documentation for the subset function has an example of subsetting rules, but no examples of subsetting transactions.

http://rss.acs.unt.edu/Rdoc/library/arules/html/subset.html

like image 569
Colonel Panic Avatar asked Sep 19 '25 19:09

Colonel Panic


1 Answers

Actually the subset syntax in the context of arules is very similar to any other context: you may want to try the following:

subset(transactions, items %in% lhs(r) & !items %in% rhs(r) )

I hope this helps!

like image 117
G Chalancon Avatar answered Sep 22 '25 09:09

G Chalancon