Wonderful people of Stack Overflow!
I am struggling with my R code. I have a whole bunch of people who have had many hospital visits - what I'm trying to get is the FIRST instance of each disease for every person. I have 6613 observations after removing duplicates, and 1306 unique id's within my dataset. So I know I need to have at least 1306 instances of first disease, and probably more seeing as some people have multiple co-morbidities.
I have arranged already by patient, and then by date. For example: What my dataset looks like
So for patient 0001, I want to get their FIRST case of angina, Chronic IHD and whatever other issues he might have (in reality some patients have 17 hospital visits, and most of them are rediagnosed.
I have tried a couple solutions found on StackOverflow, but I get ridiculous answers like 35 observations. This got me closest, using dplyr:
data_new<-data %>% group_by(iid) %>% arrange(AdmiDate) %>% slice(1L)
But I still don't have the number I would expect; like I said, I should get at least 1306.
Any help would be greatly appreciated!! Thank you so much in advance!