In this page for sake of clarity we will save the table at intermediate steps as my_table, adding flextable functions bit-by-bit. # 7 Total 3440 1469 42.7% 22 1971 57.3% 22Īfter doing this, we can progressively pipe the my_table object through more flextable formatting functions. ![]() # hospital N_Known N_Recover Pct_Recover ct_value_Recover N_Death Pct_Death ct_value_Death Table % # Get summary values per hospital-outcome group # group_by ( hospital, outcome ) %>% # Group data summarise ( # Create new summary columns of indicators of interest N = n ( ), # Number of rows per hospital-outcome group ct_value = median ( ct_blood, na.rm = T ) ) %>% # median CT value per group # add totals # bind_rows ( # Bind the previous table with this mini-table of totals linelist %>% filter ( ! is.na ( outcome ) & hospital != "Missing" ) %>% group_by ( outcome ) %>% # Grouped only by outcome, not by hospital summarise ( N = n ( ), # Number of rows for whole dataset ct_value = median ( ct_blood, na.rm = T ) ) ) %>% # Median CT for whole dataset # Pivot wider and format # mutate (hospital = replace_na ( hospital, "Total" ) ) %>% pivot_wider ( # Pivot from long to wide values_from = c ( ct_value, N ), # new values are from ct and count columns names_from = outcome ) %>% # new column names are from outcomes mutate ( # Add new columns N_Known = N_Death + N_Recover, # number with known outcome Pct_Death = scales :: percent ( N_Death / N_Known, 0.1 ), # percent cases who died (to 1 decimal) Pct_Recover = scales :: percent ( N_Recover / N_Known, 0.1 ) ) %>% # percent who recovered (to 1 decimal) select ( # Re-order columns hospital, N_Known, # Intro columns N_Recover, Pct_Recover, ct_value_Recover, # Recovered columns N_Death, Pct_Death, ct_value_Death ) %>% # Death columns arrange ( N_Known ) # Arrange rows from lowest to highest (Total row at bottom) table # print # A tibble: 7 × 8 Others such as GT and huxtable are mentione in the Suggested packages page. Likewise, the DT package is highlighted in the page Dashboards with Shiny. An example using the knitr package and its kable() function can be found in the Contact Tracing page. There are many other R packages that can be used to craft tables for presentation - we chose to highlight flextable in this page. The resulting data frame can then be passed to flextable for display formatting. Use methods from the Descriptive tables and Pivoting data pages such as tabulations, cross-tabulations, pivoting, and calculating descriptive statistics. Understand that before using flextable, you must create the summary table as a data frame. These tables can be inserted into powerpoint slides, HTML pages, PDF or Word documents, etc. This page demonstrates how to convert summary data frames into presentation-ready tables with the flextable package.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |