Produce a dataframe to summarise ticked variables
ticked_table.Rd
Takes a dataframe and produces the number and percentage for ticked variables.
Arguments
- df
Data Frame
- ...
Variables to be summarised
- group
Optional variable that defines the grouping
- sep
Optional separator between columns for splitting variable into variable and scoring. See ?tidyr::separate for more information.
- digits
Number of digits to the right of the decimal point
- condense
should the
variable
andscoring
columns in the output be condensed to one column? Only used whensep
has been specified.- total
Logical indicating whether a total column should be created
Examples
df <- data.frame(
pet_cat = sample(c("Ticked", ""), size = 100, replace = TRUE),
pet_dog = sample(c("Ticked", ""), size = 100, replace = TRUE),
pet_pig = sample(c("Ticked", ""), size = 100, replace = TRUE),
group = sample(c("A", "B", "C"), size = 100, replace = TRUE)
)
ticked_table(df, pet_cat, pet_dog, group = group, sep = "_")
#> # A tibble: 3 × 6
#> variable scoring A B C Total
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 NA NA N = 30 N = 37 N = 33 N = 100
#> 2 pet cat 14 (46.7%) 18 (48.6%) 19 (57.6%) 51 (51.0%)
#> 3 pet dog 15 (50.0%) 20 (54.1%) 19 (57.6%) 54 (54.0%)
ticked_table(df, pet_pig, pet_dog)
#> # A tibble: 3 × 2
#> scoring value
#> <chr> <chr>
#> 1 NA N = 100
#> 2 pet_pig 52 (52.0%)
#> 3 pet_dog 54 (54.0%)