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

Luisfo luisfo89 at yahoo.es
Tue Sep 13 11:10:42 CEST 2016


Dear Tom,

I think this is the line you need
   arules::subset(rules, subset=lhs %pin% "")
I found the solution here: 
http://stackoverflow.com/questions/27926131/how-to-get-items-for-both-lhs-and-rhs-for-only-specific-columns-in-arules

One more thing. For printing the rules, I needed the inspect() command 
you didn't provide.

I hope this helps.

Best,

*Luisfo Chiroque*
/PhD Student | PhD Candidate
IMDEA Networks Institute/
http://fourier.networks.imdea.org/people/~luis_nunez/ 
<http://fourier.networks.imdea.org/people/%7Eluis_nunez/>

On 09/12/2016 04:39 PM, Tom D. Harray wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


	[[alternative HTML version deleted]]



More information about the R-help mailing list