getStatsData: Get default set of statistics for variables of interest and...

View source: R/stats-getStats.R

getStatsDataR Documentation

Get default set of statistics for variables of interest and specific dataset.

Description

This set of statistics can be passed directly to the stats parameter of the package functions.
By default, statistics are extracted based on the variable(s) type and formatted with the default rules implemented in the package.

Usage

getStatsData(
  data,
  var = NULL,
  type = "default",
  extra = NULL,
  args = NULL,
  ...
)

Arguments

data

Data.frame with dataset to consider for the summary table.

var

(optional, recommended for continuous variable) Character vector with variable(s) of data, to compute statistics on.
If NULL (by default), counts of the entire dataset are computed.
It is passed to the x parameter of getStats.

type

Character vector with type of statistics to extract, among:

  • 'default': default sets of statistics, see types: 'summary-default' and 'count-default' in getStats

  • 'all': all computed statistics, see types: 'summary' and 'count' in getStats

  • any formatted statistics as implemented in getStats, see section 'Formatted statistics' in in-text table statistics.

To specify statistics for a continuous (numeric) or categorical variable separately, this vector can be named with: 'cont' or 'cat' respectively (elements not named are used for both continuous and categorical variables).

extra

List with extra statistics to include, or function to apply on each var (e.g. depending on the class of var) to get such statistic.

args

(optional) Named list with extra arguments for getStats for continuous (name: 'cont') or categorical variable (name: 'cat') specifically.

...

Extra parameters passed to the getStats function (independent of the variable type).

Value

List with statistics to compute, named by var

Author(s)

Laure Cougnaud

See Also

getStats

Examples

# default set of statistics (depending if the variable is continuous or categorical)
exampleData <- data.frame(
  USUBJID = 1 : 4, 
  WEIGHT = c(67, 78, 83, 61), 
  SEX = c("F", "M", "M", "F"), 
  stringsAsFactors = FALSE
)
getStatsData(data = exampleData, var = c("WEIGHT", "SEX"))
# all set of statistics (depending if the variable is continuous or categorical)
getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = "all")
# custom set of statistics for all variables
getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), type = c("n", "%"))
# custom set of statistics, depending on the type of the variable
getStatsData(data = exampleData, var = c("WEIGHT", "SEX"), 
  type = c(cont = "median (range)", cont = "mean (se)", cat = "n (%)"), 
  args = list(cat = list(includeName = FALSE))
)

inTextSummaryTable documentation built on Sept. 12, 2023, 5:06 p.m.