4

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

user2432675
  • 715
  • 1
  • 6
  • 14
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • 1
    Unfortunately I'm not familiar with the package in question, but have you tried investigating your object with `str()`? – Eric Fail Apr 11 '12 at 01:53

1 Answers1

5

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!

G Chalancon
  • 306
  • 3
  • 7