Skip to contents

Useful for saving space with summary tables created by continuous_table(), discrete_table(), ticked_table() or ae_table().

Usage

condense(
  df,
  first_col = variable,
  second_col = scoring,
  third_col,
  hline = TRUE,
  double.header = TRUE,
  indent = "quad"
)

Arguments

df

a data frame containing at least one column with repeated values.

first_col

variable name of the column to collapse into - should contain repeated values. Default is variable for quick use with the summary table functions.

second_col

variable name of the column to be collapsed into first_col. Default is scoring for quick use with the summary table functions.

third_col

Optionally, a third column to be collapsed into second_col.

hline

Logical indicating whether "\\hline\n" should be added at the start of each unique value in first_col. For use with xtable::xtable(). Default is TRUE.

double.header

Logical indicating whether df has a double header. Default is TRUE.

indent

Character indicating the type of indent to use (the default is "quad"):

  • "quad" uses \(\LaTeX\)'s \\quad to indent the second column (and \\qquad \\quad to indent the third column if given)

  • "hang" uses \(\LaTeX\)'s \\hangindent2em\\hangafter0 to indent the second column (and \\hangindent4em\\hangafter0 to indent the third column if given)

  • "space" uses " " to indent the second column (and " " to indent the third column if given)

Examples

  continuous_table(df = iris, Petal.Length, Petal.Width, group = Species) %>%
       condense()
#> # A tibble: 9 × 5
#>   variable                 Total             setosa         versicolor virginica
#>   <chr>                    <chr>             <chr>          <chr>      <chr>    
#> 1  NA                      N = 150           N = 50         N = 50     N = 50   
#> 2 "\\hline\n Petal.Length" 150               50             50         50       
#> 3 "\\quad Mean (SD)"       3.76 (1.77)       1.46 (0.17)    4.26 (0.4… 5.55 (0.…
#> 4 "\\quad Median (IQR)"    4.35 (1.60, 5.10) 1.50 (1.40, 1… 4.35 (4.0… 5.55 (5.…
#> 5 "\\quad Min, Max"        1, 6.9            1, 1.9         3, 5.1     4.5, 6.9 
#> 6 "\\hline\n Petal.Width"  150               50             50         50       
#> 7 "\\quad Mean (SD)"       1.20 (0.76)       0.25 (0.11)    1.33 (0.2… 2.03 (0.…
#> 8 "\\quad Median (IQR)"    1.30 (0.30, 1.80) 0.20 (0.20, 0… 1.30 (1.2… 2.00 (1.…
#> 9 "\\quad Min, Max"        0.1, 2.5          0.1, 0.6       1, 1.8     1.4, 2.5