[R] package "arules" - 'transpose' of the transactions

Michael Hahsler mhahsler at lyle.smu.edu
Sun Dec 26 17:24:17 CET 2010


Hi Kohleth,

> Suppose this is my list of transactions:
>
>
> set.seed(200)
>
> tran=random.transactions(100,3)
>
> inspect(tran)
>
>   items    transactionID
> 1 {item80}        trans1
> 2 {item8,
>    item20}        trans2
> 3 {item28}        trans3
>
>
> I want to get the 'transpose' of the data, i.e.
>
>   transactionID  items
> 1 {trans2}        item8
> 2 {trans2}        item20
> 3 {trans3}        item28
> 4 {trans1}        item80
>

This is not the transpose. The data structure you want can be created 
this way:

 > l <- LIST(tran)
 > single <- data.frame(ID=rep(names(l), lapply(l, length)), 
items=unlist(l), row.names=NULL)
 > single
       ID  items
1 trans1 item80
2 trans2  item8
3 trans2 item20
4 trans3 item28
	
>
> I tried converting tran into a matrix, then transpose it, then convert it
> back to transactions. But my dataset is actually very very large, so I
> wonder if there is any faster method?

The method above should be very fast.

-Michael

>
> Thanks




-- 
   Dr. Michael Hahsler, Visiting Assistant Professor
   Department of Computer Science and Engineering
   Lyle School of Engineering
   Southern Methodist University, Dallas, Texas

   (214) 768-8878 * mhahsler at lyle.smu.edu * http://lyle.smu.edu/~mhahsler



More information about the R-help mailing list