Discrete data summary in long format

pt_cat_wide(
  data,
  cols,
  by = ".total",
  panel = by,
  table = NULL,
  all_name = "All data",
  summarize = c("bottom", "none")
)

Arguments

data

the data frame to summarize; the user should filter or subset so that data contains exactly the records to be summarized; pmtables will not add or remove rows prior to summarizing data

cols

the columns to summarize; may be character vector or quosure

by

a grouping variable for the summary; may be given as character vector or quosure

panel

data set column name to stratify the summary

table

a named list to use for renaming columns (see details and examples)

all_name

a name to use for the complete data summary

summarize

where to put an all-data summary; choose none to omit the summary from the table

Value

An object with class pmtable; see class-pmtable.

Details

The data summary for this table is count (percent). The number of data points for each row is also summarized as n on the left hand side of the table (either on the far left or just to the right of the by column).

The notes in this table are generated with pt_cat_wide_notes().

Examples

out1 <- pt_cat_wide(pmt_first, cols = "SEXf,ASIANf")
stable(out1)
#>  [1] "\\setlength{\\tabcolsep}{5pt} "                                                      
#>  [2] "\\begin{threeparttable}"                                                             
#>  [3] "\\renewcommand{\\arraystretch}{1.3}"                                                 
#>  [4] "\\begin{tabular}[h]{lcccc}"                                                          
#>  [5] "\\hline"                                                                             
#>  [6] "\\multicolumn{1}{c}{} & \\multicolumn{2}{c}{SEXf} & \\multicolumn{2}{c}{ASIANf} \\\\"
#>  [7] "\\cmidrule(lr){2-3}"                                                                 
#>  [8] "\\cmidrule(lr){4-5}"                                                                 
#>  [9] "n & male & female & Asian & non-Asian \\\\"                                          
#> [10] "\\hline"                                                                             
#> [11] "160 & 80 (50.0) & 80 (50.0) & 66 (41.2) & 94 (58.8) \\\\"                            
#> [12] "\\hline"                                                                             
#> [13] "\\end{tabular}"                                                                      
#> [14] "\\begin{tablenotes}[flushleft]"                                                      
#> [15] "\\item Summary is count (percent)"                                                   
#> [16] "\\item n: number of records summarized"                                              
#> [17] "\\end{tablenotes}"                                                                   
#> [18] "\\end{threeparttable}"                                                               
#> attr(,"class")
#> [1] "stable"

out2 <- pt_cat_wide(pmt_first, cols = "SEXf,ASIANf", by = "FORMf")
stable(out2)
#>  [1] "\\setlength{\\tabcolsep}{5pt} "                                                            
#>  [2] "\\begin{threeparttable}"                                                                   
#>  [3] "\\renewcommand{\\arraystretch}{1.3}"                                                       
#>  [4] "\\begin{tabular}[h]{lccccc}"                                                               
#>  [5] "\\hline"                                                                                   
#>  [6] "\\multicolumn{2}{c}{} & \\multicolumn{2}{c}{SEXf} & \\multicolumn{2}{c}{ASIANf} \\\\"      
#>  [7] "\\cmidrule(lr){3-4}"                                                                       
#>  [8] "\\cmidrule(lr){5-6}"                                                                       
#>  [9] "FORMf & n & male & female & Asian & non-Asian \\\\"                                        
#> [10] "\\hline"                                                                                   
#> [11] "tablet & 130 & 62 (47.7) & 68 (52.3) & 53 (40.8) & 77 (59.2) \\\\"                         
#> [12] "capsule & 15 & 7 (46.7) & 8 (53.3) & 7 (46.7) & 8 (53.3) \\\\"                             
#> [13] "troche & 15 & 11 (73.3) & 4 (26.7) & 6 (40.0) & 9 (60.0) \\\\"                             
#> [14] "\\hline \\hline {\\bf All data} & 160 & 80 (50.0) & 80 (50.0) & 66 (41.2) & 94 (58.8) \\\\"
#> [15] "\\hline"                                                                                   
#> [16] "\\end{tabular}"                                                                            
#> [17] "\\begin{tablenotes}[flushleft]"                                                            
#> [18] "\\item Summary is count (percent)"                                                         
#> [19] "\\item n: number of records summarized"                                                    
#> [20] "\\end{tablenotes}"                                                                         
#> [21] "\\end{threeparttable}"                                                                     
#> attr(,"class")
#> [1] "stable"

if (FALSE) {
st2report(stable(out1))
st2report(stable(out2))
}