I have a data frame that looks like this:
ID Club Type
1 1 arsenal 18
2 1 arsenal 31
3 1 arsenal 32
4 1 arsenal 14
5 2 chelsea 14
6 2 chelsea 31
7 2 chelsea 15
8 2 chelsea 32
9 3 fulham 27
10 3 fulham 31
I want to transform it into something like this:
ID Club 14 15 18 27 31 32
1 1 arsenal 1 0 1 0 1 1
2 2 chelsea 1 1 0 0 1 1
3 3 fulham 0 0 0 1 1 0
So in the transformed data frame, if a type matches with a particular club then it is given a 1 value and a 0 value otherwise.
My data frame is quite a bit bigger than this (otherwise I'd be doing them all manually).
Can someone give me a suggestion as to how I'd go about doing this? My problems stem from the fact that:
- types appear multiple times
- I'm not sure how I'd go about inserting binary values (I realise I could probably do something that returns True/False)
- the ID elements should collapse into one single element