Plain single cross-table
tab_plain(
data,
row_var,
col_var,
tab_vars,
wt,
pct = "no",
diff = "tot",
comp = "tab",
color = TRUE,
digits = 0,
na = "keep",
subtext = "",
totaltab = "line",
totaltab_name = "Ensemble",
tot = NULL,
total_names = "Total",
num = FALSE,
df = FALSE
)
A data frame.
The row variable, which will be printed with one level per line,
and the column variable, which will be printed with one level per column. Numeric
variables will be used as factors. To calculate means, use tab_num
.
<tidy-select> Tab variables : a subtable is made for each combination of levels of the selected variables. Leave empty to make a simple cross-table. All tab variables are converted to factor.
A weight variable, of class numeric. Leave empty for unweighted results.
The type of percentages to calculate :
"row"
: row percentages.
"col"
: column percentages.
"all"
: frequencies for each subtable/group, if there is tab_vars
.
"all_tabs"
: frequencies for the whole (set of) table(s).
The reference cell to calculate differences (used to print colors
) :
"tot"
: by default, cells differences from total rows are calculated with
pct = "row"
, and cells differences from total columns with pct = "col"
.
"first"
: calculate cells differences from the first cell
of the row or column (useful to color temporal developments).
"no"
: not use diffs to gain calculation time.
Comparison level. When tab_vars
are present, should the
contributions to variance be calculated for each subtable/group (by default,
comp = "tab"
) ? Should they be calculated for the whole table
(comp = "all"
) ?
comp
must be set once and for all the first time you use tab_plain
,
tab_num
or tab_chi2
with rows, or tab_ci
.
TRUE
print the color percentages and means based on cells differences from
totals or reference cell, as provided by diff
. Default to FALSE
, no colors.
The number of digits to print, as a single integer.
The policy to adopt with missing values, as a single string.
"keep"
: by default, NA
's of row, col and tab variables
are printed as explicit "NA" level.
"drop"
: removes NA of row, col and tab variables.
A character vector to print rows of legend under the table.
The total table,
if there are subtables/groups (i.e. when tab_vars
is provided) :
"line"
: by default, add a general total line (necessary for
calculations with comp = "all"
)
"table"
: add a complete total table
(i.e. row_var
by col_vars
without tab_vars
).
"no"
: not to draw any total table.
The name of the total table, as a single string.
The totals :
c("col", "row")
or "both"
: by default, both total rows and total
columns.
"row"
: only total rows.
"col"
: only total column.
"no"
: remove all totals (after calculations if needed).
The names of the totals, as a character vector of length one or two.
Use syntax of type c("Total row", "Total column")
to set different names for
rows and cols.
Set to TRUE
to obtain a table with normal numeric vectors (not fmt).
Set to TRUE
to obtain a plain data.frame (not a tibble),
with normal numeric vectors (not fmt). Useful, for example, to pass the table to
correspondence analysis with FactoMineR.
A tibble
of class tabxplor_tab
. If ...
(tab_vars
)
are provided, a tab
of class tabxplor_grouped_tab
.
All non-text columns are fmt
vectors of class tabxplor_fmt
,
storing all the data necessary to print formats and colors. Columns with row_var
and tab_vars
are of class factor
: every added factor
will be
considered as a tab_vars
and used for grouping. To add text columns without
using them in calculations, be sure they are of class character
.
# NOT RUN {
# A typical workflow with tabxplor step-by-step functions :
# }
# NOT RUN {
data <- dplyr::starwars %>% tab_prepare(sex, hair_color)
data %>%
tab_plain(sex, hair_color, tot = c("row", "col"), pct = "row") %>%
tab_chi2() %>%
tab_ci(color = "after_ci")
# }
Run the code above in your browser using DataLab