This question already has an answer here:
I currently have a table set up in a basket format so that an irregular amount of data is associated with each row of the table. Such as:
01,item1,item2,item3
02,item1,item2,
03,item1,item2,item3,item4
04,item1
However, I need to change it to a normalized transactional format with only one item on each row. Such as:
01,item1
01,item2
01,item3
02,item1
02,item2
03,item1
...and so on. Is there an easy automated or programmatic way to do this? The data is currently in a MySQL database that I can export in a variety of file types, and I also have access to RStudio, and Microsoft Excel to try to do this. All the transactional resources I could find for RStudio assume that the data was already in the second format, which is what I'm trying to get to.
This question is really similar to this one. As @DWin mention in his comment you need to apply
paste( . , . sep=",")
to a splitted list.I am assuming I understand the way your data set will look once you read it into R, i.e., it will be a rectangular data frame where NA's are filled in to make the rows the same length. So this should solve the problem:
So, what you get is the following
So hopefully that helps.