I have a matrix which looks (structurally) something like this:
id 1st 2nd 3rd 4th 5th
[1,] "aaaaa1" "Tesco" "Sainsbury" "M&S" "Waitrose" "Asda"
[2,] "bbbbb2" "Sainsbury" "Tesco" "Waitrose" "Asda" "M&S"
I need to turn it into:
id shop
[1,] "aaaaa1" "Tesco"
[2,] "aaaaa1" "Sainsbury"
[3,] "aaaaa1" "M&S"
[4,] "aaaaa1" "Waitrose"
[5,] "aaaaa1" "Asda"
[6,] "bbbbb2" "Sainsbury"
[7,] "bbbbb2" "Tesco" (ETC.)
I cannot for the life of me come up with a simple solution that doesn't involve loops, and yet I know it should be straightforward.
I have tried the following, but it doesn't work at all:
library(reshape2)
meltedPredictionsMatrix = melt(widePredictionsMatrix, id.vars="id")
I feel like there's probably an even more straightforward solution that doesn't require a package, but I'm stuck.