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
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?
Thanks
--
KC
[[alternative HTML version deleted]]
Just found 'ngCMatrix' class, it must be the way to go?
---------------------------------------------
Message: 47Date: Mon, 20 Dec 2010 17:41:20 +1100
From: Kohleth Chia <kohleth@gmail.com>
To: r-help@r-project.org
Subject: [R] package "arules" - 'transpose' of the
transactions
Message-ID:
<AANLkTimmhuJ+GnThVJVT8yoMF3C5sqorkXCVGb3UT7mc@mail.gmail.com<AANLkTimmhuJ%2BGnThVJVT8yoMF3C5sqorkXCVGb3UT7mc@mail.gmail.com>>
Content-Type: text/plain
Suppose this is my list of transactions:
set.seed(200)
3)
tran=random.transactions(100,
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
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?
Thanks
--
KC
[[alternative HTML version deleted]]
[[alternative HTML version deleted]]
Michael Hahsler
2010-Dec-26 16:24 UTC
[R] package "arules" - 'transpose' of the transactions
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