[R] Consequent sorting

Jeff Reichman re|chm@nj @end|ng |rom @bcg|ob@|@net
Mon Sep 24 01:29:20 CEST 2018


Never mind.  Working with the arules package notes I was able to figure it
out

rules <- apriori(fp.trans,
                 parameter = list(supp = 0.1, conf = 0.2, target = "rules"),
                 appearance = list(rhs="Sugar", default="lhs"),
                 control = list(verbose=F))
rules.sorted <- sort(rules, by="lift")
inspect(rules.sorted)

-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Jeff Reichman
Sent: Sunday, September 23, 2018 5:18 PM
To: r-help using r-project.org
Subject: [R] Consequent sorting

r-help Forum

 I'm using the following code to sort the "right-hand side (rhs, consequent)
of the rules output from the arules packages, which works.  But what I'd
really like is the ability to subset my rules where the rhs = "some item
set"


rules_info <-
  data.frame(
    LHS = labels(lhs(rules)), 
    RHS = labels(rhs(rules)),          
    quality(rules)
  )

rules_info[ order(rules_info$RHS=), ]

For example using my code above I'm able to sort as follow's

179  {Cereals,Eggs,Tomatoes,Vinegar}   	{Bread} 0.1428571  1.0000000
1.1666667     1
184           {Eggs,Milk,Pork,Sugar}   	{Bread} 0.1428571  1.0000000
1.1666667     1
189        {Eggs,Milk,Pork,Tomatoes}    	{Bread} 0.1428571  1.0000000
1.1666667     1
1                                 {}  			{Cereals} 0.2857143
0.2857143 1.0000000     2
8                          {Vinegar}  		{Cereals} 0.1428571
1.0000000 3.5000000     1
15                        {Tomatoes} 		{Cereals} 0.1428571
0.5000000 1.7500000     1

But what I'd really like to do is just get (say) {Bread} like .

179  {Cereals,Eggs,Tomatoes,Vinegar}    {Bread} 0.1428571  1.0000000
1.1666667     1
184           {Eggs,Milk,Pork,Sugar}    {Bread} 0.1428571  1.0000000
1.1666667     1
189        {Eggs,Milk,Pork,Tomatoes}    {Bread} 0.1428571  1.0000000
1.1666667     1


Jeff Reichman


______________________________________________
R-help using r-project.org <mailto:R-help using 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