在R中按多个列以不同顺序对关联规则进行排序

时间:2019-07-17 16:22:09

标签: r sorting arules market-basket-analysis

我有交易数据并使用arules软件包生成了规则。我很难按降序排列confidence,按chi增加和按support进行排序。如何在不转换为dataframe的情况下执行此操作?

library(arules)
data(Groceries)
rules <- apriori(Groceries, parameter = list(support = 0.009, confidence = 0.25, minlen = 2))
quality(rules)$chi <- interestMeasure(rules, measure='chi', significance = TRUE, Groceries)

我已经尝试过了,但是没有用:

ordered.rules <- sort(sort(sort(rules, by ="confidence", decreasing = TRUE), by ="chi", decreasing = FALSE), by = "support", decreasing = TRUE)
inspect(ordered.rules[1:5])

library(dplyr)
rules %>% arrange(desc(rules@quality$confidence),rules@quality$chi, 
desc(rules@quality$support))

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为这应该可以解决问题:

ordered.rules2 <- sort(rules, 
  by = c(    "confidence", "chi",   "support"), 
  decreasing = c(TRUE,     FALSE,     TRUE))