r - Defining events that happen at the same time as one event -
this question has answer here:
i have time-series of events:
time <-c("01-01-1970","01-01-1971","01-01-1971","01-01-1972") event <-c("a","a","b","b") df <- data.frame(time, event) time event 1 01-01-1970 2 01-01-1971 3 01-01-1971 b 4 01-01-1972 b
now, put events happen @ same time in 1 line. in example rows 2 , 3. outcome should this:
time event
1 01-01-1970 2 01-01-1971 & b 4 01-01-1972 b
any ideas how this?
best, felix
you can use aggregate:
aggregate(df$event,by=list(df$time),fun= paste,collapse = " & ")
Comments
Post a Comment