Hi There! I have a dataset that is two unqiue identifier--one for every admission, then one for every unique patient (for example, patient "C" was admitted 3 times so has one unique Patient.ID and 3 Admit.ID). I want to count how many males and females there are, but grouped by Patient.ID instead of Admit.ID. Then, I also want to count how many females vs males dead, again grouped by Patient.Id. Here is a sample dataset and what I've done thus far that has not worked!
library(dplyr)
DF <- data.frame(
Patient.ID = c("A", "B", "C", "C", "C", "D", "D"),
Admit.ID = c("1Zz", "1Yy", "5Pp", "3Cc", "9Dd", "4Yy", "4Dd"),
Gender = c("Female", "Male", "Male", "Male", "Male", "Female", "Female"),
Male = c(0, 1, 1, 1, 1, 0, 0),
Female = c(1, 0, 0, 0, 0, 1, 1),
Survived = c(1, 0, 1, 0, 1, 1, 1),
Died = c(0, 1, 0, 1, 0, 0, 0))
I have tried:
DF%>%
group_by(Patient.ID) %>%
summarise(Female_count=n())
For which I get:
Patient.Id Female_count
1 1 1
2 2 1
3 3 2
4 4 1
5 5 1
6 6 1
7 7 1
8 8 1
9 9 1
10 10 1
... with 62,708 more rows
What I want is basically (from sample table):
2 female patients total, 0 died
2 male patients total, 2 died
Please help!