DescTools (version 0.99.18)

TOne: Create Table One Describing Baseline Characteristics

Description

Create a table summarizing continuous, categorical and dichotomous variables, optionally stratified by one or more variables, while performing adequate statistical tests.

Usage

TOne(x, grp = NA, add.length = TRUE, colnames = NULL, vnames=NULL, align = "\\l", FUN = NULL)

Arguments

x
a data.frame containing all the variables to be included in the table.

grp
the grouping variable.

add.length
logical. If set to TRUE (default), a row with the lengths of the group will be inserted as first row of the table.

colnames
a vector of columnnames for the result table.

vnames
a vector of variablenames to be placed in the first column instead of the real names.

align
the character on whose position the strings will be aligned. Left alignment can be requested by setting sep = "\\l", right alignment by "\\r" and center alignment by "\\c". Mind the backslashes, as if they are omitted, strings would be aligned to the character l, r or c respectively. Default value is "\\l", thus left alignment.

FUN
the function to be used as location and dispersion measure (typically mean/sd or median/IQR)

Value

Details

There are three types of variables currently implemented: numeric, factor and variables with only two levels.

See Also

WrdTable

Examples

Run this code
opt <- DescToolsOptions()

# define some special formats for count data, percentages and numeric results
# (those will be supported by TOne)
Fmt(abs=as.fmt(digits=0, big.mark="'"))
Fmt(per=as.fmt(digits=1, fmt="%"))
Fmt(num=as.fmt(digits=1, big.mark="'"))

TOne(x = d.pizza[, c("temperature","delivery_min","driver","wine_ordered")],
     grp=d.pizza$quality)

# define median/IQR as describing functions for the numeric variables
TOne(iris[, -5], iris[, 5],
  FUN = function(x) gettextf("%s / %s",
         Format(median(x, na.rm=TRUE), digits=1),
         Format(IQR(x, na.rm=TRUE), digits=3))
)

options(opt)

## Not run:   --  Send the whole stuff to Word
# 
# wrd <- GetNewWrd()
# ToWrd(TOne(x = d.pizza[, c("temperature","delivery_min","driver","wine_ordered")],
#            grp=d.pizza$quality))
#            ## End(Not run)

Run the code above in your browser using DataLab