diff options
Diffstat (limited to 'scripts/demo_table.R')
| -rw-r--r-- | scripts/demo_table.R | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/demo_table.R b/scripts/demo_table.R new file mode 100644 index 0000000..602cd68 --- /dev/null +++ b/scripts/demo_table.R @@ -0,0 +1,35 @@ +library(tidyverse) +library(knitr) + +orig <- read_csv("../csv/donor_demo.csv") + +data <- orig %>% + na_if("NULL") %>% + replace_na(list(Ethnicity="Unknown")) + +age_table <- tribble( + ~`Age (y)`, ~Value, + "Mean \\pm SD", paste(round(mean(data$Age), 2), "\\pm", round(sd(data$Age), 2)), + "Median (min. to max. range)", paste(median(data$Age), ' (', min(data$Age), "-", max(data$Age), ')') +) %>% +kable(format = "latex", booktabs = TRUE) + +gender_table <- tribble( + ~`Gender`, ~Value, + "Male (%)", paste(sum(data$Gender == "Male"), "(", round(sum(data$Gender == "Male")/ nrow(data), 3) * 100, ")"), + "Female", paste(sum(data$Gender == "Female"), ' (', round(sum(data$Gender == "Female") / nrow(data), 3) * 100 , ")") +) %>% +kable(format = "latex", booktabs = TRUE) + + +race_table <- tribble( + ~`Gender`, ~Value, + "Caucasian (%)", paste(sum(data$Ethnicity == "Caucasian"), "(", round(sum(data$Ethnicity == "Caucasian")/ nrow(data), 3) * 100, ")"), + "African American (Black) (%)", paste(sum(data$Ethnicity == "Black or African American"), ' (', round(sum(data$Ethnicity == "Black or African American") / nrow(data), 3) * 100 , ")"), + "Asian (%)", paste(sum(data$Ethnicity == "Asian"), ' (', round(sum(data$Ethnicity == "Asian") / nrow(data), 3) * 100 , ")"), + "Hispanic/Latino (%)", paste(sum(data$Ethnicity == "Hispanic/Latino"), ' (', round(sum(data$Ethnicity == "Hispanic/Latino") / nrow(data), 3) * 100 , ")"), + "Other (%)", paste(sum(data$Ethnicity == "Other"), ' (', round(sum(data$Ethnicity == "Other") / nrow(data), 3) * 100 , ")"), + "Unknown (%)", paste(sum(data$Ethnicity == "Unknown"), ' (', round(sum(data$Ethnicity == "Unknown") / nrow(data), 3) * 100 , ")"), +) %>% +kable(format = "latex", booktabs = TRUE) + |
