Note: This is an exercise on posting reproducible examples for an R training course
Hello,
I am working on an Ebola dataset. I am trying to create a table with the number of people in each hospital by sex. However, the output table has two rows for each hospital, one assigned m and the other f, however i want one row per hospital with two columns - one for each sex. Any help is appreciated thanks.
install and load packages
pacman::p_load(tidyverse, kableExtra)
data
surv_data β data.frame(
stringsAsFactors = FALSE,
NA,
case_id = c(β694928β,β86340dβ,
β92d002β,β544bd1β,
β6056baβ,βeb5aebβ,
βe64e04β,β5a65bbβ,
β2ae019β,β7ca4c0β),
sex = c(βmβ,βfβ,βfβ,βfβ,
βfβ,βfβ,βfβ,βmβ,
βmβ,βmβ),
hospital = c(βOtherβ,
βPort Hospitalβ,NA,NA,NA,
βPort Hospitalβ,NA,
βPort Hospitalβ,
βOtherβ,
βPort Hospitalβ)
)
Create a table with the number of people in each hospital by sex
hospital_table β surv_data %>%
group_by(hospital, sex) %>%
summarise(count = n()) %>%
ungroup() %>%
kable(format = βhtmlβ) %>%
kable_styling(full_width = FALSE) %>%
column_spec(1, bold = TRUE) %>%
row_spec(0, bold = TRUE, color = βwhiteβ, background = β#0073e6β) %>%
scroll_box(width = β500pxβ, height = β300pxβ)
hospital_table