Hi everyone, I am new to R and I thank you ahead for any help!
I have created a MasterTable with a large hospital dataset that includes different demographic data for children who are admitted that includes year and length of hospital stay (LOS) in days. I want to find out the median LOS per year. In the sample dataset, I only made it span 5 years, but the actual dataset spans many more years. How do I figure out the median without creating a separate table where I filter out the dataset per year?
Dataset:
MasterTable <- data.frame(
Patient.ID = c("A", "B", "C", "C", "C", "D", "D", "E", "F", "G", "G"),
Admit.ID = c("1Zz", "1Yy", "5Pp", "3Cc", "9Dd", "4Yy", "4Dd", "2Aa", "6Rr", "8Ee", "7Pp"),
Gender = c("Female", "Male", "Male", "Male", "Male", "Female", "Female", "Male", "Female", "Male", "Male"),
Died = c(0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0),
Discharge.year = c("2017", "2014", "2015", "2016", "2015", "2017", "2018", "2014", "2018", "2015", "2016"),
LOS.Days = c(0.59, 4.35, 1.89, 6.02, 2.76, 1.99, 0.96, 11.52, 1.57, 4.16, 3.74))
Created on 2021-04-23 by the reprex package (v2.0.0)