contingency_table_by | R Documentation |
Counts by the specified two variables and the pivots the count data frame wider to a two-dimensional contingency table. Please note that the resulting data frame is suitable for convenient output or use with functions that work on matrix-like data, but does not fulfill the tidy data criteria.
contingency_table_by(.tbl, var1, var2, na.rm = F, add_margins = F)
.tbl |
A data frame |
var1 |
First column to count by |
var2 |
Second column to count by |
na.rm |
Shall NA values be removed prior to counting? |
add_margins |
Add row- and column wise margins as extra column and row |
A data frame
library(magrittr) if (requireNamespace("datasets", quietly = TRUE)) { mtcars %>% contingency_table_by(cyl, gear) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.