我正在做一个给定交易 x 和一组规则 y 的函数,如果 x 作为一个整体是 y 的子集,那么我对它很感兴趣,因为我可以根据规则进行推荐(我正在使用“杂货”数据集)我正在尝试使用它来执行此操作%ain%
,但看起来 RStudio 似乎无法识别它,我将把我的代码和它抛出的错误留给你。
install.packages("arules")
library(arules)
myfunction <- function(t,w,z){
lav <- which (t %ain% w,arr.ind=TRUE)
lav <- z[lav,]
lav <- unique(lav)
return (lav)
}
data("Groceries")
x <- list(c("pip fruit","root vegetables","yogurt","soda","fruit/vegetable juice"))
reglas = apriori(Groceries, parameter=list(supp=0.0006, conf=0.98))
t <- as(x,"transactions")
z <- slot(reglas,"rhs")
w <- slot(reglas,"lhs")
inspect(myfunction(t,w,z))
这是错误:
error in evaluating the argument 'x' in selecting a method for function 'which': Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘%ain%’ for signature ‘"transactions", "itemMatrix"’