This function summarizes your data in a specific way and returns an object that can be converted into a latex table.

pt_cont_wide(
  data,
  cols,
  by = ".total",
  panel = by,
  table = NULL,
  units = NULL,
  digits = new_digits(),
  all_name = "All data",
  fun = cont_wide_fun,
  na_fill = "--",
  id_col = "ID"
)

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; may be 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)

units

a named list to use for unit lookup (see details and examples)

digits

a digits object (see new_digits())

all_name

a name to use for the complete data summary

fun

the data summary function (see details)

na_fill

value to fill with when all values in the summary are missing

id_col

the ID column name

Value

An object with class pmtable; see class-pmtable.

Details

The default summary function is cont_wide_fun(). Please review that documentation for details on the default summary for this table.

The notes for this table are generated by pt_cont_wide_notes().

Custom summary function

The summary function (fun) should take value as the first argument and return a data frame or tibble with one row and one column named summary. The function can also accept an id argument which is a vector of IDs that is the same length as value. Be sure to include ... to the function signature as other arguments will be passed along. Make sure your function completely formats the output ... it will appear in the table as you return from this function. See cont_wide_fun() for details on the default implementation.

Examples

pmtables:::cont_wide_fun(rnorm(100))
#> # A tibble: 1 × 1
#>   summary            
#>   <chr>              
#> 1 0.189 (0.992) [100]

out <- stable(pt_cont_wide(pmt_first, cols = "AGE,WT,SCR"))
out
#>  [1] "\\setlength{\\tabcolsep}{5pt} "                                 
#>  [2] "\\begin{threeparttable}"                                        
#>  [3] "\\renewcommand{\\arraystretch}{1.3}"                            
#>  [4] "\\begin{tabular}[h]{lll}"                                       
#>  [5] "\\hline"                                                        
#>  [6] "AGE & WT & SCR \\\\"                                            
#>  [7] "\\hline"                                                        
#>  [8] "33.7 (8.83) [160] & 70.7 (12.8) [157] & 1.36 (0.986) [160] \\\\"
#>  [9] "\\hline"                                                        
#> [10] "\\end{tabular}"                                                 
#> [11] "\\begin{tablenotes}[flushleft]"                                 
#> [12] "\\item Summary is mean (sd) [count]"                            
#> [13] "\\end{tablenotes}"                                              
#> [14] "\\end{threeparttable}"                                          
#> attr(,"class")
#> [1] "stable"

if (FALSE) { # \dontrun{
st2report(out)
} # }