2

When I attempt to subset transactions with arules it returns the entire transaction database/item matrix.

I've referenced the following post, but it doesn't seem to work correctly: R arules - subset of transactions that match a rule

Any hints as to where I am going wrong?

require(arules)
data("Adult")
## Mine association rules.
rules <- apriori(Adult, 
                 parameter = list(supp = 0.5, conf = 0.9, target = "rules", minlen = 2))
summary(rules)
sub_rules <- rules[1]
inspect(sub_rules)
sub_trans <- subset(Adult, items %in% lhs(sub_rules))
rwdvc
  • 455
  • 5
  • 13
  • If i understand you correctly, this might point you in the right direction https://stackoverflow.com/questions/23281315/arules-how-find-the-data-matching-an-lhsrule-in-r-or-an-sql-where-clause – Rutger Nov 15 '17 at 21:48

1 Answers1

2

I think your code should work and this is a bug in arules. For now you can do the following:

subset(Adult, items %in% unlist(as(lhs(sub_rules), "list")))

It basically translates the item in the LHS into a character string.

It will be fixed in the next release (arules_1.5-5).

Michael Hahsler
  • 2,965
  • 1
  • 12
  • 16