I have some data that looks like this:
UserID Category
------ --------
1 a
1 b
2 c
3 b
3 a
3 c
A I'd like to binary-encode this grouped by UserID
: three different values exist in Category
, so a binary encoding would be something like:
UserID encoding
------ --------
1 "1, 1, 0"
2 "0, 0, 1"
3 "1, 1, 1"
i.e., all three values are present for UserID
= 3
, so the corresponding vector is "1, 1, 1"
.
Is there a way to do this without doing a bunch of CASE WHEN
statements? There may be dozens of possible values in Category