This Analyze Function uses the new S3 generic function s_summary() to summarize
different variables that are arranged in columns.
Additional standard formatting arguments are available.
Usage
summarize_colvars(
  lyt,
  ...,
  .stats = c("n", "mean_sd", "median", "range", "count_fraction"),
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)Arguments
- lyt
 (
layout)
input layout where analyses will be added to.- ...
 arguments passed to
s_summary().- .stats
 (
character)
statistics to select for the table.- .formats
 (named
characterorlist)
formats for the statistics.- .labels
 (named
character)
labels for the statistics (without indent).- .indent_mods
 (named
integer)
indent modifiers for the labels.
Formatting arguments
These additional formatting arguments can be passed to the layout creating function:
- .stats
 (
character)
names of the statistics to use- .indent_mods
 (
integer)
named vector of indent modifiers for the labels- .formats
 (
characterorlist)
named vector of formats for the statistics- .labels
 (
character)
named vector of labels for the statistics (without indent)
Examples
dta_test <- data.frame(
  USUBJID = rep(1:6, each = 3),
  PARAMCD = rep("lab", 6 * 3),
  AVISIT = rep(paste0("V", 1:3), 6),
  ARM = rep(LETTERS[1:3], rep(6, 3)),
  AVAL = c(9:1, rep(NA, 9)),
  CHG = c(1:9, rep(NA, 9))
)
## Default output within a `rtables` pipeline.
basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT") %>%
  split_cols_by_multivar(vars = c("AVAL", "CHG")) %>%
  summarize_colvars() %>%
  build_table(dta_test)
#>                         A                       B                     C        
#>                 AVAL         CHG        AVAL         CHG       AVAL       CHG  
#> ———————————————————————————————————————————————————————————————————————————————
#> V1                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   7.5 (2.1)   2.5 (2.1)   3.0 (NA)    7.0 (NA)    NA (NA)   NA (NA)
#>   Median         7.5         2.5         3.0         7.0        NA        NA   
#>   Min - Max   6.0 - 9.0   1.0 - 4.0   3.0 - 3.0   7.0 - 7.0   NA - NA   NA - NA
#> V2                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   6.5 (2.1)   3.5 (2.1)   2.0 (NA)    8.0 (NA)    NA (NA)   NA (NA)
#>   Median         6.5         3.5         2.0         8.0        NA        NA   
#>   Min - Max   5.0 - 8.0   2.0 - 5.0   2.0 - 2.0   8.0 - 8.0   NA - NA   NA - NA
#> V3                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   5.5 (2.1)   4.5 (2.1)   1.0 (NA)    9.0 (NA)    NA (NA)   NA (NA)
#>   Median         5.5         4.5         1.0         9.0        NA        NA   
#>   Min - Max   4.0 - 7.0   3.0 - 6.0   1.0 - 1.0   9.0 - 9.0   NA - NA   NA - NA
## Selection of statistics, formats and labels also work.
basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT") %>%
  split_cols_by_multivar(vars = c("AVAL", "CHG")) %>%
  summarize_colvars(
    .stats = c("n", "mean_sd"),
    .formats = c("mean_sd" = "xx.x, xx.x"),
    .labels = c(n = "n", mean_sd = "Mean, SD")
  ) %>%
  build_table(dta_test)
#>                       A                    B                  C       
#>                AVAL       CHG       AVAL       CHG      AVAL     CHG  
#> ——————————————————————————————————————————————————————————————————————
#> V1                                                                    
#>   n             2          2          1         1        0        0   
#>   Mean, SD   7.5, 2.1   2.5, 2.1   3.0, NA   7.0, NA   NA, NA   NA, NA
#> V2                                                                    
#>   n             2          2          1         1        0        0   
#>   Mean, SD   6.5, 2.1   3.5, 2.1   2.0, NA   8.0, NA   NA, NA   NA, NA
#> V3                                                                    
#>   n             2          2          1         1        0        0   
#>   Mean, SD   5.5, 2.1   4.5, 2.1   1.0, NA   9.0, NA   NA, NA   NA, NA
## Use arguments interpreted by `s_summary`.
basic_table() %>%
  split_cols_by("ARM") %>%
  split_rows_by("AVISIT") %>%
  split_cols_by_multivar(vars = c("AVAL", "CHG")) %>%
  summarize_colvars(na.rm = FALSE) %>%
  build_table(dta_test)
#>                         A                       B                     C        
#>                 AVAL         CHG        AVAL         CHG       AVAL       CHG  
#> ———————————————————————————————————————————————————————————————————————————————
#> V1                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   7.5 (2.1)   2.5 (2.1)   3.0 (NA)    7.0 (NA)    NA (NA)   NA (NA)
#>   Median         7.5         2.5         3.0         7.0        NA        NA   
#>   Min - Max   6.0 - 9.0   1.0 - 4.0   3.0 - 3.0   7.0 - 7.0   NA - NA   NA - NA
#> V2                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   6.5 (2.1)   3.5 (2.1)   2.0 (NA)    8.0 (NA)    NA (NA)   NA (NA)
#>   Median         6.5         3.5         2.0         8.0        NA        NA   
#>   Min - Max   5.0 - 8.0   2.0 - 5.0   2.0 - 2.0   8.0 - 8.0   NA - NA   NA - NA
#> V3                                                                             
#>   n               2           2           1           1          0         0   
#>   Mean (SD)   5.5 (2.1)   4.5 (2.1)   1.0 (NA)    9.0 (NA)    NA (NA)   NA (NA)
#>   Median         5.5         4.5         1.0         9.0        NA        NA   
#>   Min - Max   4.0 - 7.0   3.0 - 6.0   1.0 - 1.0   9.0 - 9.0   NA - NA   NA - NA