Skip to content

Commit

Permalink
Adding snippet: two demographics tables
Browse files Browse the repository at this point in the history
ref #38
  • Loading branch information
ARPeters committed Oct 16, 2023
1 parent 0151e43 commit 39b8457
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion snippets/demographics-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,43 @@ Different Approaches for Creating Demographics Tables
Code:

```r
bla bla
# Creating data set to work on

# sex <- sample(c("female", "male") , size = 1000, replace = TRUE, prob = c(0.5, 0.5) )
# ethnicity <- sample(c("Hispanic", "Not Hispanic") , size = 1000, replace = TRUE, prob = c(0.3, 0.7) )
# race <- sample(c("Asian", "African American" , "Native American", "Caucasian") , size = 1000, replace = TRUE, prob = c(0.2, 0.3, 0.1, 0.4) )
#
# ds_sample <-
# cbind(
# sex,
# ethnicity,
# race
# ) |>
# as.data.frame()

# Creating tables
table_1 <-
ds_sample |>
gtsummary::tbl_summary() |>
gtsummary::bold_labels()

table_2 <-
ds_sample |>
gtsummary::tbl_strata(
strata = ethnicity,

.tbl_fun = ~ .x |>
gtsummary::tbl_summary(
by = sex,

type = list(everything() ~ "categorical"),

statistic = list(everything() ~ "{p}% ({N_obs})")
)
) |>
gtsummary::bold_labels()

table_1
table_2

```

0 comments on commit 39b8457

Please sign in to comment.