tableone.Rd
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") )
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 |
pos_label | label of the positive |
test | logical; if set to |
caption | when |
output | how the table is output; can be "text" or "text2" for regular console output or any of |
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. |
a table; the output varies based on the output
parameter.
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)#>#> #> #>#>#>#>#>#> #> ──────────────────────────────────────────────────────────────────────────────────────────────────────── #> 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 #> ────────────────────────────────────────────────────────────────────────────────────────────────────────