[R] Arules Package: Rules subset with 'empty' left hand side (lhs)

Tom D. Harray tomdharray at gmail.com
Mon Sep 12 16:39:06 CEST 2016


Hello,

subsets of association rules (with respect to support, confidence, lift, or
items) can be obtained with the arules::subset() function; e.g.

  rm(list = ls(all.names = TRUE))
  library(arules)
  set.seed(42)

  x <- lapply(X = 1:500, FUN = function(i)
    sample(x = 1:10, size = sample(1:5, 1), replace = FALSE)
  )
  x <- as(x, 'transactions')

  rules <- apriori(
    data = x,
    parameter = list(target = 'rules', minlen = 1, maxlen = 2,
      support = 0.10, confidence = 0.32)
  )
  rules <- arules::sort(x = rules, decreasing = TRUE, by ='support')

gives the rules
3  {}  => {1} 0.330   0.3300000  1.0000000
2  {}  => {3} 0.326   0.3260000  1.0000000
1  {}  => {2} 0.320   0.3200000  1.0000000
20 {3} => {1} 0.120   0.3680982  1.1154490
21 {1} => {3} 0.120   0.3636364  1.1154490
16 {4} => {3} 0.114   0.3677419  1.1280427
(...)

However, I cannot figure out (help/web) how to get the subset for the rules
with empty left hand side (lhs) like subset(rules, lhs == ''). I  could run the
apriori() function twice and adjust the min/maxlen parameters as a band
aid fix.


So my question is: How do I subset() association rules with empty lhs?


Thanks and regards,

Dirk



More information about the R-help mailing list