[R] transaction object - how to coerce this data

jim holtman jholtman at gmail.com
Wed Sep 1 13:51:11 CEST 2010


try this:

> x.t <- split(x$item, x$basketID)
> x.t
$`1`
[1] "bread"  "cheese" "milk"

$`2`
[1] "bread"  "cheese" "eggs"

$`3`
[1] "bread"  "cheese" "beer"

> dput(x.t)
structure(list(`1` = c("bread", "cheese", "milk"), `2` = c("bread",
"cheese", "eggs"), `3` = c("bread", "cheese", "beer")), .Names = c("1",
"2", "3"))
>


On Wed, Sep 1, 2010 at 12:52 AM, pdb <philb at philbrierley.com> wrote:
>
> Hi,
>
> I am wanting to look at frequent item sets using the arules package. I need
> to transform my data into a "transactions" object. The data I read in from a
> file has 2 columns, an ID and an item. How do I convert data like this into
> a transactions object?
>
> I've tried
> class? transactions
> but it only confuses me.
>
> My data is like this....
>
> basketID        item
> 1       bread
> 1       cheese
> 1       milk
> 2       bread
> 2       cheese
> 2       eggs
> 3       bread
> 3       cheese
> 3       beer
>
> and from what I gather it should be like this?
>
>  data <- list(
>  c("bread","cheese","milk"),
>  c("bread","cheese","eggs"),
>  c("bread","cheese","beer")
> )
>
> so I can use:
>
> t <- as(data, "transactions")
>
> Thanks in advance.
>
> Phil
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/transaction-object-how-to-coerce-this-data-tp2402613p2402613.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list