arules 子集在 arules 包的新版本 (1.5-2) 中不起作用

arules subset not working in the new version (1.5-2) of arules package

我最近通过 Arules 包更新到 1.5-2 版,因为我无法从规则集中对项目列表进行子集化,当我尝试进行子集化时出现以下错误 “结构错误 (seq(length(labels)), names = labels)[i] : 无效的下标类型 'S4'" 这是一个例子

library(arules)
data("Groceries")

#generate Rules without second record to create an itemset
rules <- apriori(Groceries[-2],parameter = list(supp = 0.05, conf = 0.2,target = "rules"))

#Create an itemlist with second record
enter code here`basket <- Groceries[2]
rulesMatchLHS <- is.subset(rules@lhs,basket)
suitableRules <- rulesMatchLHS & !(is.subset(rules@rhs,basket))
#output
inspect(rules[suitableRules])

提前致谢

你的子集向量看起来像一个稀疏矩阵,但需要一个密集的逻辑向量:

suitableRules

7 x 1 sparse Matrix of class "lgCMatrix"
                   {tropical fruit,yogurt,coffee}
{}                                              |
{yogurt}                                        |
{whole milk}                                    .
{rolls/buns}                                    .
{whole milk}                                    .
{other vegetables}                              .
{whole milk}                                    .

as.logical(suitableRules)
[1]  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE

inspect(rules[as.logical(suitableRules)])
    lhs         rhs          support   confidence lift     count
[1] {}       => {whole milk} 0.2555420 0.2555420  1.000000 2513 
[2] {yogurt} => {whole milk} 0.0560301 0.4018964  1.572722  551