pt_demographics | R Documentation |
This function makes a single table from both continuous and categorical data.
pt_demographics(
data,
cols_cont,
cols_cat,
span = NULL,
units = NULL,
table = NULL,
stat_name = "Statistic",
stat_width = 2,
summarize_all = TRUE,
all_name = "Summary",
fun = dem_cont_fun,
notes = pt_demographics_notes(),
paneled = TRUE,
denom = c("group", "total")
)
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_cont |
the continuous data columns to summarize; this argument may be specified as a character vector, comma-separated string or quosure |
cols_cat |
the categorical columns to summarize; this argument may be specified as a character vector, comma-separated string or quosure |
span |
variable name for column spanner |
units |
optional units for each summarized column; must be a named list
where the names correspond with continuous data columns in |
table |
a named list to use for renaming columns (see details and examples) |
stat_name |
name of statistic column |
stat_width |
width (in cm) of the statistic column |
summarize_all |
logical; if |
all_name |
a character name for the all data summary invoked by
|
fun |
The summary function to use for summarizing the continuous
data; the default is |
notes |
notes a character vector of notes to place under the table |
paneled |
logical; if |
denom |
the denominator to use when calculating percent for each level;
|
When a continuous data summary function (fun
) is passed, the user should
also pass a set of notes that explain the summary statistics produced
by that function. If no notes are passed, no notes will appear under the
table.
The categorical data is summarized using pt_cat_long()
.
The default summary function for continuous variables is dem_cont_fun()
.
Please review that documentation for details on the default summary for this
table.
If you wish to define your own function, please ensure the output is in the same format. Any number of columns is acceptable.
An object of class pmtable
.
An object with class pmtable; see class-pmtable.
pt_cont_long()
, pt_cat_long()
out <- pt_demographics(
data = pmt_first,
cols_cont = c(Age = "AGE", Weight = "WT"),
cols_cat = c(Sex = "SEXf", Race = "ASIANf"),
units = list(WT = "kg"),
span = c(Study = "STUDYf")
)
out <- pt_demographics(
data = pmt_first,
cols_cont = "AGE,WT",
cols_cat = "SEXf,ASIANf",
paneled = FALSE,
span = "FORMf"
)
tab <- stable(out)
pmtables:::pt_demographics_notes()
new_fun <- function(value = seq(1,5), name = "", ...) {
value <- value[!is.na(value)]
tibble::tibble(
`mean` = sig(mean(value)),
`median` = sig(median(value)),
`min-max` = paste0(sig(range(value)), collapse = " - ")
)
}
out <- pt_demographics(
data = pmt_first,
cols_cont = "AGE,WT",
cols_cat = "SEXf,ASIANf",
fun = new_fun
)
pmtables:::dem_cont_fun(rnorm(20))
new_fun(rnorm(20))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.