0

我想用这个arules包来练习用R挖掘关联规则。数据是

datt <- structure(list(Item1 = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 
0L), Item2 = c(0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L), Item3 = c(0L, 
1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L), Item4 = c(0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L), Item5 = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 
0L, 0L, 1L), Item6 = c(0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L
), Item7 = c(0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L), Item8 = c(0L, 
1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L), Item9 = c(0L, 1L, 1L, 1L, 
0L, 0L, 0L, 0L, 1L, 0L), Item10 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L)), .Names = c("Item1", "Item2", "Item3", "Item4", 
"Item5", "Item6", "Item7", "Item8", "Item9", "Item10"), row.names = c(2L, 
3L, 4L, 5L, 6L, 8L, 9L, 10L, 11L, 12L), class = c("cast_df", 
"data.frame"))

通过做

table5 <- as(datt, "transactions")

出现此错误:

Error in as(datt, "transactions") : 
  no method or default for coercing “cast_df” to “transactions”

我该怎么做才能将我的对象转换为“交易”对象?

4

5 回答 5

3

也许你忘记加载arules包。

library(arules)
于 2020-01-03T00:32:07.890 回答
1

尝试这个 :

as(as.matrix(datt), "transactions")
transactions in sparse format with
 10 transactions (rows) and
 10 items (columns)

错误在这里很明显:

no method or default for coercing “cast_df” to “transactions”

class(datt)cast_df并且没有这种类型的强制方法(as)。

请注意,通常您在使用包时不需要手动进行强制转换arules,该函数会尝试在内部进行正确的强制转换。例如 :

dissimilarity(x=as.matrix(datt),method='cosine') ## works
dissimilarity(x=datt,method='cosine')            ## you get the same coercion error
于 2013-04-10T10:35:01.193 回答
1

对我来说这有效

install.packages("arules")
于 2016-07-30T08:59:51.433 回答
0

这些问题与在 markdown 中的代码块之前加载库有关。您已在 R 环境中加载了该库,因此代码可以正常工作。但是对于针织,您需要在降价中加载库。

于 2021-05-30T20:56:55.263 回答
0

我得到了同样的错误,它是通过添加库(矩阵)修复的

希望有帮助

于 2019-02-15T14:22:23.803 回答