![]() ![]() As above, these outputs can be produced for the whole data frame set, or by group. You can also use sum() to return the number of rows that meet certain logical criteria. One major advantage of dplyr and summarise() is the ability to return more advanced statistical summaries like median(), mean(), max(), min(), sd() (standard deviation), and percentiles. Thus, the final step of calculating proportions (denominator sum(n)) is still grouped by outcome. ![]() Importantly - as it finishes its process, count() also ungroups the age_cat grouping, so the only remaining data grouping is the original grouping by outcome. This function further groups the data by age_cat and returns counts for each outcome- age-cat combination. First, the data are grouped on outcome via group_by(). It relies on different levels of data grouping being selectively applied and removed. Use table() from base R if you do not have access to the above packagesĪge_summary % count ( age_cat ) %>% # group and count by gender (produces "n" column) mutate ( # create percent of column - note the denominator percent = scales :: percent ( n / sum ( n ) ) ) # print age_summary # age_cat n percentīelow is a method to calculate proportions within groups.Use tbl_summary() from gtsummary to produce detailed publication-ready tables.Use summarise() and count() from dplyr for more complex statistics, tidy data frame outputs, or preparing data for ggplot().Use get_summary_stats() from rstatix to easily generate data frames of numeric summary statistics for multiple columns and/or groups.Use tabyl() from janitor to produce and “adorn” tabulations and cross-tabulations.Consider the points below as you choose the tool for your situation. png/.jpeg/.html image), and ease of post-processing. Some of the factors to consider include code simplicity, customizeability, the desired output (printed to R console, as data frame, or as “pretty”. You have several choices when producing tabulation and cross-tabulation summary tables. ![]() Use this page to decide which approach works for your scenario. This page covers how to create* the underlying tables, whereas the Tables for presentation page covers how to nicely format and print them.*Įach of these packages has advantages and disadvantages in the areas of code simplicity, accessibility of outputs, quality of printed outputs. This page demonstrates the use of janitor, dplyr, gtsummary, rstatix, and base R to summarise data and create tables with descriptive statistics. 46 Version control and collaboration with Git and Github.33 Demographic pyramids and Likert-scales.19 Univariate and multivariable regression. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |