I have a quite interesting problem that I am looking a smart and possible efficient solution for.
I have a data frame that looks like this.
# A tibble: 6 x 6
track_id tag1 tag2 tag3 tag4 tag5
<int> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1550729 54087 109806 46869 183258 54337
2 1184201 201327 3668 46208 205245 189631
3 3763749 194264 194413 3424 91383 205245
4 2674608 198998 107401 2327 4425 107398
5 1999180 54087 4425 75574 239459 2397
6 3048820 11242 205245 2474 11056 72354
What I would like is to keep the track_id in the first row but to explode the tags, and where one track has the particular ID I would like to put a true value, namely one.
To be clearer, let's suppose I start from a smaller one:
track_id tag1 tag2
1 1550729 54087 109806
2 1184201 201327 3668
After the transformation I would like to get at something like
track_id 54087 109806 201327 3668
1 1550729 1 1 0 0
2 1184201 0 0 1 1
Is this something possible quickly or I should roll out a solution by hand?