Quantcast
Viewing all articles
Browse latest Browse all 4448

How to reshape data as transactions in R

@pagal_guy wrote:

Hello,

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 = ' ')
transaction.id <- unique(transact$transaction_id)
#Create vectors of each transaction:
transaction.1 <- subset(transact,transaction_id == transaction.id[1],select = c('transaction_id','product_id'))
transaction.1_transpose <- as.data.frame(t(transaction.1[,2]))

This gives me:
Image may be NSFW.
Clik here to view.

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

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles