View source: R/R05-Statistical_tools.R
camr_build_demographics_table | R Documentation |
A function that will build a data frame that is well- formatted to easily create a flextable object.
camr_build_demographics_table(df, grp, funcs)
df |
A data frame that contains variables named according to the specification created by Kevin Potter (i.e. XXX.FFF.Var_name), where XXX is a 3-letter subset code and FFF is a 3-letter format identifier. |
grp |
A variable name that contains the grouping variable for the demographics table. |
funcs |
A named list of purrr-style lambda functions
where the names follow one of 3 conventions (below). Note:
for all CHR variables, the function operates on the unique
values within that variable, NOT on the variable itself.
Further, the value
|
A data frame.
William Schmitt
# Example data frame
df <- data.frame(
SSS.CHR.Group = c('G1', 'G1', 'G2', 'G2'),
SBJ.INT.Age = c(45, 47, 48, 52),
SBJ.CHR.Race = c('White', 'White', 'Asian', 'Black')
)
# Runs function on CHR and INT variables
dt <- camr_build_demographics_table(
df,
SSS.CHR.Group,
list(
'INT' = ~paste0(round(mean(.), 2)),
'CHR' = ~paste0(./n*100, '%')
)
)
# Runs function on SBJ.INT and SBJ.CHR variables
dt <- camr_build_demographics_table(
df,
SSS.CHR.Group,
list(
'SBJ.INT' = ~paste0(round(mean(.), 2)),
'SBJ.CHR' = ~paste0(./n*100, '%')
)
)
# Runs function on individual columns
dt <- camr_build_demographics_table(
df,
SSS.CHR.Group,
list(
'SBJ.INT.Age' = ~paste0(round(mean(.), 2)),
'SBJ.CHR.Race' = ~paste0(./n*100, '%')
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.