Created
September 26, 2025 10:01
-
-
Save thanhyds1998/afdbf57a742a573c6b27267b16088ae9 to your computer and use it in GitHub Desktop.
Create automatic table with gtsummary package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tbl_summary(M2SGS, include = c("SEXE", "M1_SP", "DISTANCE_BDX"), statistic = list( all_continuous() ~ "{mean} ({sd})" ), digits = ( all_continuous() ~ c(1, 1) ) ) | |
# Explication: | |
## statistic = list(all_continuous() ~ "{mean} ({sd})") | |
### Normally, continuous variables are summarized with median (IQR) by default. Here, you override that: For all continuous variables, display: mean (standard deviation) | |
### The "{}" are placeholders — {mean} is replaced by the mean, {sd} by the standard deviation. | |
## d) digits = (all_continuous() ~ c(1, 1)) | |
### Controls number formatting (number of decimal places). For all continuous variables, both the mean and standard deviation will be shown with 1 decimal place. | |
### Example: 45.3 (12.7) instead of 45.34567 (12.7345). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment