My df looks like,
id event time_diff
1 a 0
1 b 10
3 a 0
3 b 10
3 c 5
3 d 20
3 d 30
I'm trying to reshape the above data in the following way,
id a b c d
1 0 10 NA NA
2 0 10 5 50
I tried,
df2 <- dcast(df,id~event,fill="time_diff")
and also the following,
df2 = df %>%
group_by(id) %>%
spread(Event,time_diff)
But both are not yielding the required results, any help would be appreciated.
PS: The main issue is it has duplicate events in different time frame, which I want to aggregate