tableone: Produces a tbl1 object, which contains a two-way table...

Description Usage Arguments Value Examples

View source: R/tidy.table.one.R

Description

Produces a tbl1 object, which contains a two-way table grouped by the specificed grouping variable.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
tableone(
  df,
  grpvar,
  testTypes = NULL,
  d = 1,
  p.digits = 3,
  fisher.simulate.p = FALSE,
  trunc_binary = TRUE,
  lbl = "",
  caption = ""
)

Arguments

df

A data frame or tibble with Hmisc-brand labels.

grpvar

The quoted name of a grouping variable that splits df into two cohorts.

testTypes

A vector of length nrow(df) containing "t" for a t-test or "w" for a Wilcoxon rank-sum test; applies only to continuous variables. Leave NULL to allow the function to choose for you based on the distance between the mean and median.

d

Number of significant digits to report in (non-p-value) numbers in the tbl1 object.

p.digits

Number of significant digits to report in p-values.

fisher.simulate.p

If TRUE use simulated p-values for Fisher's exact test. Default is FALSE.

trunc_binary

If TRUE print only one row for categorical variables with 2 levels. If FALSE, binary variables are printed on two rows, with the variable name and p-value on a row above. Default is TRUE.

lbl

LaTeX label to be passed to tx() for labeling the table in a LaTeX document.

caption

Text to be passed to tx() or md() to caption the table.

Value

A tbl1 object that can be formatted by tx() or md().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
foo <- as_tibble(iris) %>% 
  filter(Species!="setosa") %>% 
    apply.labels(c("Sepal length", 
                   "Sepal width",
                   "Petal length",
                   "Petal width",
                   "Species")) %>%
    mutate(Species = fct_drop(Species))
md(tableone(foo, grpvar="Species"))

md(tableone(foo, grpvar="Species",
                 testTypes=c("t", "t", "t", "t", "t")))

md(tableone(foo, grpvar="Species",
                 testTypes=c("t", "t", "w", "w", "w")))

trahelyk/trahelyk_pkg documentation built on June 14, 2021, 9:25 p.m.