0

I am trying to subset such that all items on the rhs and lhs are set to 1 but this is not working. Is there some other way I can make sure my items on the LHS and RHS of rules are all '1' only? I have used the following code.

rules = apriori(cosdat1, parameter=list(support=0.28, confidence=0.3, minlen=2, target="rules"))
summary(rules)

    rules.sub <- subset(rules, subset = lhs %in% c("Bag=1","Blush=1","Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1","Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1","Lip.Gloss=1","Lipstick=1","Eyeliner=1"));
    rules.sub

    rules.sub1 <- subset(rules, subset = rhs %in% c("Bag=1","Blush=1","Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1","Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1","Lip.Gloss=1","Lipstick=1","Eyeliner=1"));
    rules.sub1
Sal-laS
  • 11,016
  • 25
  • 99
  • 169
Shraddha Avasthy
  • 161
  • 3
  • 13
  • I also tried: nrules<-rules[sapply(as(items(rules), "list"), function(x) all(grepl("=1$", x)))] but then I have only 1 item on both lhs and rhs- I do not want to restrict the number of items to that low a number – Shraddha Avasthy Sep 09 '18 at 16:26

1 Answers1

0

Since you did not provide your data, it is a little hard to confirm, but I believe that you were almost there. Your first subset statement gives rules with the lhs containing only =1's (no restriction on the rhs). Your second subset statement gives rules with the rhs containing only =1's (no restriction on the lhs). To make the restriction apply to both sides, apply the second statement to the result of the first.

rules.sub1 <- subset(rules.sub, subset = rhs %in% c("Bag=1","Blush=1",
      "Nail.Polish=1","Brushes=1","Concealer=1","Eyebrow.Pencils=1","Bronzer=1",
      "Lip.liner=1","Mascara=1","Eye.shadow=1","Foundation=1",
      "Lip.Gloss=1","Lipstick=1","Eyeliner=1"));
G5W
  • 36,531
  • 10
  • 47
  • 80
  • Valid point. I made the change and still my rules look like the following (with items=0): {Bag=0,Brushes=0,Mascara=1} => {Eye.shadow=1} {Bag=0,Lip.liner=0,Mascara=1} => {Eye.shadow=1} {Bag=0,Mascara=1} => {Eye.shadow=1} {Bag=0,Brushes=0,Eyebrow.Pencils=0,Mascara=1} => {Eye.shadow=1} {Nail.Polish=0,Mascara=1} => {Eye.shadow=1} – Shraddha Avasthy Sep 09 '18 at 18:02
  • When you examine the first subset, does `rules.sub` contain rules where the lhs has zeros? – G5W Sep 09 '18 at 19:04