I have a data frame called df that contains 2 columns; user and artist.
head(df, 5)
user artist
1 3bd73256-3905-4f3a-97e2-8b341527f805 betty blowtorch
2 f2fb0ff0-5679-42ec-a55c-15109ce6e320 die Ärzte
3 b3ae82c2-e60b-4551-a76d-6620f1b456aa melissa etheridge
4 3d6bbeb7-f90e-4d10-b440-e153c0d10b53 elvenking
5 bbd2ffd7-17f4-4506-8572-c1ea58c3f9a8 juliette & the licks
I want to create another data frame that gives each entry in the artist column a row that is then represented by a 0 or 1 based on if the user ID has an entry for that artist. Here is an example of the results I am trying to get:
user betty blowtorch die Ärzte melissa etheridge elvenking juliette & the licks
1 3bd73256-3905-4f3a-97e2-8b341527f805 1 0 0 0 0
2 3bd73256-3905-4f3a-97e2-8b341527f805 0 1 0 0 0
3 f2fb0ff0-5679-42ec-a55c-15109ce6e320 0 1 0 0 0
4 b3ae82c2-e60b-4551-a76d-6620f1b456aa 0 0 1 0 0
5 3d6bbeb7-f90e-4d10-b440-e153c0d10b53 0 0 0 1 0
6 bbd2ffd7-17f4-4506-8572-c1ea58c3f9a8 0 0 0 0 1
7 bbd2ffd7-17f4-4506-8572-c1ea58c3f9a8 0 0 0 1 0
If the user ID appears in df multiple times, then I need a new row for that user, so each row will only have one 1 value (see above example). Any suggestions?