Description Usage Arguments Value Examples
The format_table function is an S3 generic. It currently has methods for formatting the output of the freq_table and mean_table functions. For example, a mean and 95 formatted as 24.00 (21.00 - 27.00) by default.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | format_table(.data, ...)
## S3 method for class 'mean_table'
format_table(.data, digits = 2,
stats = "mean and ci", ...)
## S3 method for class 'mean_table_grouped'
format_table(.data, digits = 2,
stats = "mean and ci", ...)
## S3 method for class 'freq_table_one_way'
format_table(.data, digits = 2,
stats = "percent and ci", ...)
## S3 method for class 'freq_table_two_way'
format_table(.data, digits = 2,
stats = "row percent and ci", ...)
|
.data |
A data frame of an accepted class. |
... |
Other parameters to be passed on. |
digits |
Determines the number of decimal places to display. Passed to the "nsmall =" parameter of the format function. Note: Changing the digits argument to format_table will change the number of digits displayed, but does not change the underlying rounding of the value. That must be changed in the digits argument to mean_table or freq_table. |
stats |
Options for this parameter control which formatted statistics are returned. For mean_table and mean_table_grouped classes, the options are "mean and ci" (default) and "n and mean". For the freq_table_one_way class, the options are "percent and ci" and "n and percent". For the freq_table_two_way class, the options are "row percent and ci" (default), "n and row percent", "percent and ci", "n and percent". |
A tibble.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | library(tidyverse)
library(bfuncs)
data(mtcars)
# Overall mean table with defaults
mtcars %>%
mean_table(mpg) %>%
format_table()
#> # A tibble: 1 x 2
#> response_var mean_95
#> <chr> <chr>
#> 1 mpg 20.09 (17.92 - 22.26)
# Grouped means table with defaults
mtcars %>%
group_by(cyl) %>%
mean_table(mpg) %>%
format_table()
#> # A tibble: 3 x 4
#> response_var group_var group_cat mean_95
#> <chr> <chr> <dbl> <chr>
#> 1 mpg cyl 4 26.66 (23.63 - 29.69)
#> 2 mpg cyl 6 19.74 (18.40 - 21.09)
#> 3 mpg cyl 8 15.10 (13.62 - 16.58)
# One-way frequency tables with defaults
mtcars %>%
group_by(cyl) %>%
mean_table(mpg) %>%
format_table()
#> # A tibble: 2 x 3
#> var cat percent_95
#> <chr> <dbl> <chr>
#> 1 am 0 59.38 (40.94 - 75.50)
#> 2 am 1 40.62 (24.50 - 59.06)
# Two-way frequency tables with defaults
mtcars %>%
group_by(am, cyl) %>%
freq_table() %>%
format_table()
#> # A tibble: 6 x 5
#> row_var row_cat col_var col_cat percent_row_95
#> <chr> <dbl> <chr> <dbl> <chr>
#> 1 am 0 cyl 4 15.79 (4.78 - 41.20)
#> 2 am 0 cyl 6 21.05 (7.58 - 46.44)
#> 3 am 0 cyl 8 63.16 (38.76 - 82.28)
#> 4 am 1 cyl 4 61.54 (32.30 - 84.29)
#> 5 am 1 cyl 6 23.08 (6.91 - 54.82)
#> 6 am 1 cyl 8 15.38 (3.43 - 48.18)
#' # Two-way frequency tables with with stats = "n and row percent"
mtcars %>%
group_by(am, cyl) %>%
freq_table(output = all) %>% # Don't forget output = all
format_table(stats = "n and row percent")
#> # A tibble: 6 x 5
#> row_var row_cat col_var col_cat n_percent_row
#> <chr> <dbl> <chr> <dbl> <chr>
#> 1 am 0 cyl 4 3 (15.79)
#> 2 am 0 cyl 6 4 (21.05)
#> 3 am 0 cyl 8 12 (63.16)
#> 4 am 1 cyl 4 8 (61.54)
#> 5 am 1 cyl 6 3 (23.08)
#> 6 am 1 cyl 8 2 (15.38)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.