I have a data frame where id can have multiple event types
> head(eventtype, 10)
id event_type
1 6597 event_type 11
2 8011 event_type 15
3 2597 event_type 15
4 5022 event_type 15
5 5022 event_type 11
6 6852 event_type 11
7 6852 event_type 15
8 5611 event_type 15
9 14838 event_type 15
10 14838 event_type 11
I want to convert it into a format
id event_type 1 event_type 2 event_type 3 ... event_type 50
14838 0 0 0 ... 0
What is the best way to achieve this in R? Is there any package? I have tried using dummies:
new_my_data <- dummy.data.frame(eventtype, names = c("event_type1", "event_type2", "event_type3", "event_type4", "event_type5")
but it doesn't work. I tried to search as well but could see a solution to this specific problem. Nearly all posts assume that one hot encoding is known to all.
Please help.