New to R: If I have multiple observations for the same ID. How can I tell if event 1 occurred before, after or at the same time as event 2 for each ID?
ID is an integer. The number of observations for each ID varies. Time is just the time period; 1,2,...t. Events 1 and 2 are 0/1 dummies.
I need to be able to count the number of times event 1 occurs before, after or at the same time as event 2. Seems like this should be pretty simple/straight forward, but I haven't had any luck.
UPDATE: this should give a sense of the data:
my.df <- structure(list(ID = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L), Time = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 1L, 2L, 3L, 4L,
5L), Event.1 = c(0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L,
1L), Event.2 = c(1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L,
0L)), .Names = c("ID", "Time", "Event.1", "Event.2"), class = "data.frame", row.names = c(NA,
-12L))
Thanks!