Folks,
I'm stumped with the following challenge. I have a data set that looks like this:
BuyerID Fruit.1 Fruit.2 Fruit.3 Amount.1 Amount.2 Amount.3
879 Banana Apple 4 3
765 Strawberry Apple Orange 1 2 4
123 Orange Banana 1 1 1
11 Strawberry 3
773 Kiwi Banana 1 2
What I would like to do is to simplify the data (if possible) and collapse the "Fruit" and "Amount" variables
BuyerID Fruit Amount Total Count
879 "Banana" "Apple" 4 3 7 2
765 "Strawberry" "Apple" "Orange" 1 2 4 7 3
123 "Orange" "Banana" 1 1 1 3 2
11 "Strawberry" 3 3 1
773 "Kiwi" "Banana" 1 2 3 2
I have tried using c() and rbind() but they do not produce the results that I want - I've tried the tip here: data.frame rows to a list as well but am not too sure whether this is the best way to simplify my data.
This is so that presumably it would be easier for me to deal with fewer variables to count the occurrence of certain items for example (e.g. 60% buyers purchase Banana).
I hope this is doable - am also open to any suggestions. Any solutions appreciated!
Thank you.