sorting - How to sort association rules by lhs or rhs in R -


i have set of rules apriori algorithm. sorting them lift, confidence or support easy:

rules.sorted = sort(rules, by="lift") 

but let's have small set of rules few different rhs elements. view rules sorted rhs elements (alphabetically). there way that?

i.e this:

    lhs       rhs support   confidence lift     1   {a}    => {b} 0.3919252 0.9431280  1.930940 2   {b}    => {a} 0.3919252 0.8024194  1.930940 3   {e,c}  => {a} 0.3535204 0.7995546  1.924047 4   {f,i}  => {f} 0.3924175 0.9005650  1.868281 5   {h}    => {g} 0.4194978 0.9659864  1.864941 6   {c,d}  => {a} 0.3653373 0.7141482  1.718525 

to this:

    lhs       rhs support   confidence lift      2   {b}    => {a} 0.3919252 0.8024194  1.930940 3   {e,c}  => {a} 0.3535204 0.7995546  1.924047 6   {c,d}  => {a} 0.3653373 0.7141482  1.718525 1   {a}    => {b} 0.3919252 0.9431280  1.930940 4   {f,i}  => {f} 0.3924175 0.9005650  1.868281 5   {h}    => {g} 0.4194978 0.9659864  1.864941 

here example of rules work with:

library(arules) download.file("http://archive.ics.uci.edu/ml/machine-learning-databases/mushroom/agaricus-lepiota.data", "mush.data"); dataset = read.table("mush.data", header = f, sep=",", na.strings= "*") tr <- as(dataset, "transactions") param  = new("apparameter", "confidence" = 0.9, "support" = 0.7, "minlen"= 2l, "maxlen" = 2l, "target" = "rules")  rules <-apriori(tr,param) dput(rules) 

extract basic information rules object data frame, this:

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

then sort normal data frame:

rules_info[ order(rules_info$rhs), ] 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -