在r中按不同顺序按多列对关联规则进行排序
Sort association rules by multiple columns in different order in r
我有交易数据和使用 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))
提前致谢!
我认为这应该可以解决问题:
ordered.rules2 <- sort(rules,
by = c( "confidence", "chi", "support"),
decreasing = c(TRUE, FALSE, TRUE))
我有交易数据和使用 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))
提前致谢!
我认为这应该可以解决问题:
ordered.rules2 <- sort(rules,
by = c( "confidence", "chi", "support"),
decreasing = c(TRUE, FALSE, TRUE))