count_by | R Documentation |
Similar to dplyr::count()
, but also adds the relative proportion and
a percent-formatted string of the relative proportion,
and allows to specify the column names.
count_by( .tbl, ..., column_names = c("n", "rel", "percent"), percentage_label_decimal_places = 1, add_grouping = T, na.rm = F )
.tbl |
A data frame |
... |
Columns / expressions by which to group / which shall be used for counting. |
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). |
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? |
The counted data frame
library(magrittr) if (requireNamespace("survival", quietly = TRUE)) { survival::aml %>% count_by(x) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.