我有交易数据并使用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))
谢谢!
答案 0 :(得分:1)
我认为这应该可以解决问题:
ordered.rules2 <- sort(rules,
by = c( "confidence", "chi", "support"),
decreasing = c(TRUE, FALSE, TRUE))