This function provides a wrapper around furniture::table1 that allows it to utilize Hmisc::label as variable labels. It also automatically converts logicals to factors so logical dataframe columns are included in the table.

tableone(
  df,
  ...,
  group = NULL,
  neg_label = "No",
  pos_label = "Yes",
  test = TRUE,
  caption = NULL,
  output = "text",
  type = c("pvalues", "simple", "condensed")
)

Arguments

df

a dataframe

...

a list of columns to be included in the table

group

a group to split the columns by

neg_label

label of the negative group

pos_label

label of the positive group

test

logical; if set to TRUE then the appropriate bivariate tests of significance are performed if splitby has more than 1 level. A message is printed when the variances of the continuous variables being tested do not meet the assumption of Homogeneity of Variance (using Breusch-Pagan Test of Heteroskedasticity) and, therefore, the argument `var.equal = FALSE` is used in the test.

caption

when output != "text"; option is passed to knitr::kable

output

how the table is output; can be "text" or "text2" for regular console output or any of kable()'s options from knitr (e.g., "latex", "markdown", "pandoc"). A new option, 'latex2', although more limited, allows the variable name to show and has an overall better appearance.

type

what is displayed in the table; a string or a vector of strings. Two main sections can be inputted: 1. if test = TRUE, can write "pvalues", "full", or "stars" and 2. can state "simple" and/or "condense". These are discussed in more depth in the details section below.

Value

a table; the output varies based on the output parameter.

Examples

diamonds <- ggplot2::diamonds diamonds$expensive <- diamonds$price > 500 Hmisc::label(diamonds$depth) <- "Depth" Hmisc::label(diamonds$table) <- "Table" Hmisc::label(diamonds$price) <- "Price" Hmisc::label(diamonds$clarity) <- "Clarity" Hmisc::label(diamonds$cut) <- "Cut" Hmisc::label(diamonds$expensive) <- "Expensive" diamonds %>% tableone(depth, table, price, clarity, expensive, group = cut)
#> Registered S3 methods overwritten by 'furniture': #> method from #> as.data.frame.table1 table1 #> print.table1 table1
#> Breusch-Pagan Test of Heteroskedasticity suggests `var.equal = FALSE` in oneway.test() for: Depth
#> Breusch-Pagan Test of Heteroskedasticity suggests `var.equal = FALSE` in oneway.test() for: Table
#> Breusch-Pagan Test of Heteroskedasticity suggests `var.equal = FALSE` in oneway.test() for: Price
#>
#> #> ──────────────────────────────────────────────────────────────────────────────────────────────────────── #> cut #> Fair Good Very Good Premium #> n = 1610 n = 4906 n = 12082 n = 13791 #> Depth 64.0 (3.6) 62.4 (2.2) 61.8 (1.4) 61.3 (1.2) #> Table 59.1 (3.9) 58.7 (2.9) 58.0 (2.1) 58.7 (1.5) #> Price 4358.8 (3560.4) 3928.9 (3681.6) 3981.8 (3935.9) 4584.3 (4349.2) #> Clarity #> I1 13% 2% 0.7% 1.5% #> SI2 28.9% 22% 17.4% 21.4% #> SI1 25.3% 31.8% 26.8% 25.9% #> VS2 16.2% 19.9% 21.4% 24.3% #> VS1 10.6% 13.2% 14.7% 14.4% #> VVS2 4.3% 5.8% 10.2% 6.3% #> VVS1 1.1% 3.8% 6.5% 4.5% #> IF 0.6% 1.4% 2.2% 1.7% #> Expensive: Yes 99.6% 95.3% 94.5% 98.4% #> Ideal P-Value #> n = 21551 #> 61.7 (0.7) <.001 #> 56.0 (1.2) <.001 #> 3457.5 (3808.4) <.001 #> <.001 #> 0.7% #> 12.1% #> 19.9% #> 23.5% #> 16.7% #> 12.1% #> 9.5% #> 5.6% #> 97.1% <.001 #> ────────────────────────────────────────────────────────────────────────────────────────────────────────