How to reshape data as transactions in R




I have some data which looks like:

From this I am trying to create a transactions dataset via:

transact <- subset(sales,select = c('product_id','time_id','customer_id'))
transact$transaction_id <- paste(as.character(transact$time_id),as.character(transact$customer_id),sep = ' ') <- unique(transact$transaction_id)
#Create vectors of each transaction:
transaction.1 <- subset(transact,transaction_id ==[1],select = c('transaction_id','product_id'))
transaction.1_transpose <-[,2]))

This gives me:

Is this the right approach?
How do I do this for the whole dataset?



it is a question of test how to build such a table. I usually use deployer for this type of work, I shall transform transaction id as a factor and then do a group_by, this will give me data set grouped by translation id.
If you se ply then you can use all the mutate , filter etc…
Hope this help.


thanks a lot @Lesaffrea,

I did in this way:

transaction.trns <- sqldf('select transaction_id,product_id from transact group by transaction_id')
transactions <-
#Now use the split function to create transactions data:
lst1 <- split(transaction.trns[,"transaction_id"], transaction.trns[,"product_id"]) 
transactions_data <- as(lst1, "transactions")