Cross categorical variables with numeric ones, and get a table of means. Superseded by
tab(), which builds the same table whenever col_vars holds numeric variables – and
everything around it (both kinds of variable at once, colours, totals, tests). It stays the
smallest entry point into the numeric aggregate core, and takes the same arguments resolved
by the same rules, so its numbers agree with tab()'s cell for cell.
Usage
tab_num(
data,
row_var,
col_vars,
tab_vars,
wt,
...,
num = FALSE,
df = FALSE,
.fine = NULL,
.by_table = FALSE
)Arguments
- data
A data frame.
- row_var
Singular aliases of
row_vars/col_vars(which now accept several variables). Kept working.- col_vars
<tidy-select> The column variable(s) — see
row_vars. An interaction is writtena*b, as intab_reg(), and onlycol_varstakes one: two factors give one column per observed cell of the pair, a number crossed with a factor one mean column per level. Seevignette("tabxplor").- tab_vars
<tidy-select> Tab variables: one subtable per combination of their levels. Leave empty for a simple cross-table.
- wt
A weight variable, of class numeric. Leave empty for unweighted results.
- ...
Every other argument of
tab()–color,ci,tot,digits, ... – passed by name. Seetab(); a typo gets a suggestion.- num
Set to
TRUEto obtain a table with normal numeric vectors (not fmt).- df
Set to
TRUEto 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.- .fine, .by_table
Internal.
.fineis a pre-computed count-aggregate to roll up from instead of scanning the raw data (used bytab_countsand the scan-fusion path);.by_tableforces the table-by-table path.
Value
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.
Examples
# \donttest{
data <- dplyr::storms |> dplyr::filter(!is.na(wind))
tab_num(data, category, wind, tot = "row",
color = "difference", color_signif = "guaranteed_effect")
#> # A tabxplor tab: 7 × 2
#> category wind
#> <mean (cv)>
#> 1 1 71 (cv 8%)
#> 2 2 89 (cv 4%)
#> 3 3 104 (cv 4%)
#> 4 4 122 (cv 5%)
#> 5 5 146 (cv 4%)
#> 6 NA 38 (cv 31%)
#> 7 Total 50 (cv 51%)
#> # standardized difference (Total): -0.4 -0.2 -0.1 -0 +0 +0.1 +0.2 +0.4 [all that is significant is colored, error-adjusted]
# }