0

I want to use the arules package to practice mining association rules with R. The data is

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"))

By doing

table5 <- as(datt, "transactions")

this error turns up:

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

What can I do to convert my object into a 'transactions' object?

sebastian-c
  • 15,057
  • 3
  • 47
  • 93
causjc
  • 9
  • 1
  • 3

5 Answers5

3

Maybe you forget to load arules package.

library(arules)
oklm
  • 135
  • 1
  • 10
1

Try this :

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

The error is explicit here :

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

class(datt) is cast_df and no coercing method(as) for this type.

Note that generally you don't need to do the coercion manually when you use the arules package, the function will try to do the right coercion internally. For example :

dissimilarity(x=as.matrix(datt),method='cosine') ## works
dissimilarity(x=datt,method='cosine')            ## you get the same coercion error
agstudy
  • 119,832
  • 17
  • 199
  • 261
  • Thx for your help.But in my pc,there is error with your way.The error is below:ERROE:as(as.matrix(datt), "transactions") : no method or default for coercing “cast_matrix” to “transactions” – causjc Apr 10 '13 at 13:28
1

for me this works

install.packages("arules")
masoud2011
  • 896
  • 9
  • 10
0

I got the same error and it was fixed by adding library(Matrix)

Hope that helps

0

These issues are regarding loading the library before the chunk of code in markdown. You have the library loaded in the R environment, so the code works. But for knitting, you need to load the library in the markdown.

Sia
  • 13
  • 3