count_at {tidytidbits} | R Documentation |
Count by multiple variables
Description
Count by multiple variables
Usage
count_at(
.tbl,
.vars,
.grouping = vars(),
label_style = "long",
long_label_column_names = c("variable", "category"),
column_names = c("n", "rel", "percent"),
na_label = "missing",
percentage_label_decimal_places = 1,
add_grouping = T,
na.rm = F
)
Arguments
.tbl |
A data frame |
.vars |
A list of variables (created using vars()) for which |
.grouping |
Additional grouping to apply prior to counting |
label_style |
Character vector containing one of "wide" and "long" or both.
|
long_label_column_names |
Character vector of size 2: If label_style contains "long", the names for the additional meta columns for variable and category |
column_names |
vector if size 1 to 3, giving the names of (in order if unnamed, or named with n, rel, percent) the column containing the count, the relative proportion, and the latter formatted as a percent label. If a name is not contained, it will not be added (requires named vector). |
na_label |
If na.rm=F, label to use for counting NA values |
percentage_label_decimal_places |
Decimal precision of the percent label |
add_grouping |
Shall a pre-existing grouping be preserved for counting (adding the newly specified grouping)? Default is yes, which differs from group_by. |
na.rm |
Shall NA values be removed prior to counting? |
Value
A data frame concatenated from individual count_by results, with labels as per label_style.
Examples
library(magrittr)
library(datasets)
library(dplyr)
mtcars %>% count_at(vars(gear, cyl))