0

I've been working on rewriting my code that worked with data.frames to work with ffdf. I had two columns, and after a lot of fuss I've managed to do a split and get a list with the following look:

data=
$A
1 2 3
$B
4 5 6

where A,B are the "baskets" or groupings, and "1 2 3" specific grouped items. What I want now is to convert these to transactions and hopefully manage to do an apriori. I've tried the simple

as(i, "transaction")

which worked well when "data" was generated from a data.frame but now it produces an error:

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

I've seen that duplicate items can cause these problems, so I've eliminated those but the error remains.

Centar 15
  • 127
  • 1
  • 13
  • just to make it clear the original data set looked like: X Y A 1 A 2 A 3 B 4 B 5 B 6 – Centar 15 Aug 29 '16 at 13:41
  • 1
    You could improve your question. Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). A good post usually provides minimal input data, the desired output data & code tries - all copy-paste-run'able in a new/clean R session (i.e. also include library calls etc.). – lukeA Aug 29 '16 at 13:58

2 Answers2

1

Should be no problem:

library(arules)
data <- list(A=1:3, B=4:6)

showMethods("coerce", classes="transactions")
# Function: coerce (package methods)
# from="data.frame", to="transactions"
# from="list", to="transactions"
# from="matrix", to="transactions"
# from="ngCMatrix", to="transactions"
# from="tidLists", to="transactions"
# from="transactions", to="data.frame"
# from="transactions", to="list"
# from="transactions", to="matrix"
# from="transactions", to="tidLists"

class(data)
# [1] "list"
as(data, "transactions")
# transactions in sparse format with
#  2 transactions (rows) and
#  6 items (columns)

Also note that you wrote as(i, "transaction") and not as(i, "transactions").

lukeA
  • 53,097
  • 5
  • 97
  • 100
0

Luckily, it wasn't actually necessary to do this step! One can just send a list as the one described and apriori will try to figure it out! Thanks to agstudy from the following link.

Cannot convert dataframe to transactions object

I'll leave the question open if someone else needs a solution to it.

Community
  • 1
  • 1
Centar 15
  • 127
  • 1
  • 13