contingency_table_by {tidytidbits} | R Documentation |
Create data frame formed like a contingency-table
Description
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.
Usage
contingency_table_by(.tbl, var1, var2, na.rm = F, add_margins = F)
Arguments
.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 |
Value
A data frame
Examples
library(magrittr)
if (requireNamespace("datasets", quietly = TRUE))
{
mtcars %>% contingency_table_by(cyl, gear)
}
[Package tidytidbits version 0.3.2 Index]