-->

R arules - subset of transactions that match a rul

2019-04-12 06:05发布

问题:

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

回答1:

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!



标签: r subset arules