Count by multiple variables
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
)
A data frame
A list of variables (created using vars()) for which count_by
is to be called
Additional grouping to apply prior to counting
Character vector containing one of "wide" and "long" or both.
"wide": Include labels in wide format, i.e., for each variable one column named as variable and giving the label for the corresponding count, but NA for all rows from different variables
"long": Include two meta columns, one giving the variable that is counted (value from .vars), the second giving the label (which value/category of the variable is counted?).
Character vector of size 2: If label_style contains "long", the names for the additional meta columns for variable and category
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).
If na.rm=F, label to use for counting NA values
Decimal precision of the percent label
Shall a pre-existing grouping be preserved for counting (adding the newly specified grouping)? Default is yes, which differs from group_by.
Shall NA values be removed prior to counting?
A data frame concatenated from individual count_by results, with labels as per label_style.
# NOT RUN {
library(magrittr)
library(datasets)
library(dplyr)
mtcars %>% count_at(vars(gear, cyl))
# }
Run the code above in your browser using DataLab