View source: R/stats-getStats.R
getStats | R Documentation |
This set of statistics can be passed directly to the stats
parameter
of the of the package functions.
getStats(
type = "summary",
includeName = TRUE,
x = NULL,
nDecCont = getMaxNDecimals,
nDecN = 0,
nDecm = nDecN,
formatPercentage = inTextSummaryTable::formatPercentage
)
type |
Character vector with type of statistics (multiple are possible).
Available statistics are specified in the section 'Formatted statistics' and
formatting in 'Statistics formatting' in
|
includeName |
Logical, should the statistics name be included (TRUE by default)?
This is applied for the statistic names used in each for the set defined in |
x |
(optional, recommended for continuous variable) Numeric vector
for which the statistics should be computed on. |
nDecCont |
Integer with base number of decimals
for continuous variable, or function returning this number based on |
nDecN , nDecm |
Integer with number of decimals for number of subjects/records (0 by default). |
formatPercentage |
Function used to format the percentages
(see |
Expression (or call object) containing
function to extract requested summary statistics.
If multiple type
are specified, they are combined to a list.
Names of the list will be typically used to name the statistic
in the summary table.
Laure Cougnaud
getStatsData
## default set of statistics are available for:
# for count table:
getStats("count")
getStats("n (%)")
getStats("n")
getStats("%")
getStats("m")
getStats("%m")
getStats("m (%)")
# for continuous variable:
getStats("summary")
getStats("mean (se)")
getStats("mean (sd)")
getStats("median (range)")
getStats("median\n(range)")
getStats(c("Mean", "SE"))
## to not include statistic name in the table
getStats("median\n(range)", includeName = FALSE)
getStats(c("summary", "median\n(range)"), includeName = FALSE)
## to extract the number of decimals based on a continuous variable (see ?getMaxNDecimals)
exampleData <- data.frame(
USUBJID = 1 : 4,
WEIGHT = c(67, 78, 83, 61),
SEX = c("F", "M", "M", "F"),
stringsAsFactors = FALSE
)
getStats(type = c('median (range)', 'mean (se)'), x = exampleData$WEIGHT)
# compare with when 'x' is not specified:
getStats(type = c('median (range)', 'mean (se)'))
## custom function to format the percentages:
getStats(type = "count", formatPercentage = function(x) round(x, 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.