I am working with a data frame where each row is a patient with a particular illness. There is a column for their age category, and several columns with text (Yes or No) as to whether or not they are experiencing a particular symptom. Example provided below
set.seed(1)
Sick <- data.frame(age=sample(c("Infant", "Child", "Adult", "Elderly"), size=20, replace = TRUE),
cough= sample(c("Yes", "No"), size=20, replace = TRUE),
fever= sample(c("Yes", "No"), size=20, replace = TRUE),
chills= sample(c("Yes", "No"), size=20, replace = TRUE),
fatigue=sample(c("Yes", "No"), size=20, replace = TRUE))
What I am trying to get is a nicely structured frame that indicates how many patients in each category experience the symptom where the columns are the age categories and the rows are the count of how many people in that category experienced that symptom. The code below shows what I want my end result to be.
Count <- data.frame(symptom=c("cough", "fever", "chills", "fatigue"),
Infant=c(5, 1, 4, 2),
Child= c(4, 3, 2, 4),
Adult= c(2, 3, 1, 5),
Elderly = c(1, 0, 0, 0))
I know I could create this with the table and rbind functions, however, I was wondering if anyone had advice on how to streamline this? The real frame has about 10 age categories and 25 symptoms, so doing lots of tables may not be the most efficient.
Thank you for any and all help!