Create a two way data table
Usage
tbl_2var(
data,
formula,
row_pct = c("hide", "show"),
digits = 3,
caption = NULL,
na_rm = TRUE
)
Arguments
- data
A data frame.
- formula
The variables to tabulate. Should be given in formula notation
var1~var2
. Changing the order of the variables will swap the table axes.- row_pct
Should row percents be included in each cell? Defaults to "hide" with the only other possible value being "show".
- digits
The number of digits to round to. Defaults to 3.
- caption
An optional caption for the table. Defaults to
NULL
, but a sensible default is provided within the function.- na_rm
Should missing values be removed? Defaults to TRUE.
Value
An object of class flextable. If in an interactive session, the table will be viewable immediately.
Examples
tbl_2var(mtcars, cyl~gear)
tbl_2var(mtcars, cyl~gear, row_pct = "show")
tbl_2var(mtcars, cyl~gear, caption = "This is the new caption")
# Will give an error
try(tbl_2var(mtcars, Cyl~Gear))
#> Error in value[[3L]](cond) :
#> Could not complete the process. Perhaps you spelled the dataset name or
#> a variable name wrong? Hint: R is case-sensitive.