-->

无法将数据帧的交易对象(Cannot convert dataframe to transactio

2019-10-29 13:52发布

我想用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”

我能做些什么,以我的对象转换为“交易”对象?

Answer 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


Answer 2:

对于我这种工作

install.packages("arules")


Answer 3:

我得到了同样的错误,它是由添加库固定(矩阵)

希望帮助



文章来源: Cannot convert dataframe to transactions object
标签: r arules