Produce a dataframe to summarise discrete variables
discrete_table.Rd
Takes a dataframe and produces the number and percentage for discrete variables.
Usage
discrete_table(
df = .,
...,
group = .,
time = .,
total = TRUE,
n = FALSE,
missing = "Missing",
accuracy = 0.1,
condense = FALSE
)
Arguments
- df
Data Frame
- ...
Variables to be summarised
- group
Optional variable that defines the grouping
- time
Optional variable for repeated measures (currenlty must me used with group)
- total
Logical indicating whether a total column should be created
- n
Logical indicating whether percentages should be out of n (
n = TRUE
) or N (n = FALSE
)- missing
String determining what missing data will be called (if
n = TRUE
). Default is "Missing".- accuracy
see details of
scales::percent
- condense
should the
variable
andscoring
columns in the output be condensed to one column?
Examples
library(ggplot2) # for the data
discrete_table(df = mpg, drv, group = manufacturer)
#> # A tibble: 4 × 18
#> variable scoring Total audi chevrolet dodge ford honda hyundai jeep
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 NA NA N = 234 N = 18 N = 19 N = … N = … N = 9 N = 14 N = 8
#> 2 drv 4 103 (44.0%) 11 (61… 4 (21.1%) 26 (… 13 (… 0 (0… 0 (0.0… 8 (1…
#> 3 drv f 106 (45.3%) 7 (38.… 5 (26.3%) 11 (… 0 (0… 9 (1… 14 (10… 0 (0…
#> 4 drv r 25 (10.7%) 0 (0.0… 10 (52.6… 0 (0… 12 (… 0 (0… 0 (0.0… 0 (0…
#> # ℹ 8 more variables: `land rover` <chr>, lincoln <chr>, mercury <chr>,
#> # nissan <chr>, pontiac <chr>, subaru <chr>, toyota <chr>, volkswagen <chr>
discrete_table(df = mpg, drv)
#> # A tibble: 4 × 3
#> variable scoring value
#> <chr> <chr> <chr>
#> 1 NA NA N = 234
#> 2 drv 4 103 (44.0%)
#> 3 drv f 106 (45.3%)
#> 4 drv r 25 (10.7%)