Firstly, I saw a posting for a conversion from basket to single but not the reverse, and I saw another, similar posting that was never answered.
I have data in stack form like so:
ID Product
A Prod1
A Prod2
B Prod1
B Prod2
B Prod3
C Prod1
I need it to look like this:
ID Products
A Prod1, Prod2
B Prod1, Prod2, Prod3
C Prod1
I tried unstack
then unlist
but those didn't work.
How do you convert from single to basket?
Picking up where @MrFlick left off, if you want to convert your rows to columns, you can do so, but you'll need to add a "time" variable to your data first. This is easily done with
getanID
from my "splitstackshape" package.From there, you can use your preferred method to go from a "long" dataset to a "wide" one. For instance, here I've shown how to use the
reshape
function from base R anddcast.data.table
from the "data.table" package: