Near-identical alternative to dplyr::count()
.
f_count(
data,
...,
wt = NULL,
sort = FALSE,
.order = df_group_by_order_default(data),
name = NULL,
.by = NULL,
.cols = NULL
)f_add_count(
data,
...,
wt = NULL,
sort = FALSE,
.order = df_group_by_order_default(data),
name = NULL,
.by = NULL,
.cols = NULL
)
A data.frame
of frequency counts by group.
A data frame.
Variables to group by.
Frequency weights.
Can be NULL
or a variable:
If NULL
(the default), counts the number of rows in each group.
If a variable, computes sum(wt)
for each group.
If TRUE
, will show the largest groups at the top.
Should the groups be calculated as ordered groups?
If FALSE
, this will return the groups in order of first appearance,
and in many cases is faster.
If TRUE
(the default), the groups are returned in sorted order,
exactly the same way as dplyr::count
.
The name of the new column in the output.
If there's already a column called n
,
it will use nn
.
If there's a column called n
and n
n,
it'll use nnn
, and so on, adding n
s until it gets a new name.
(Optional). A selection of columns to group by for this operation. Columns are specified using tidy-select.
(Optional) alternative to ...
that accepts
a named character vector or numeric vector.
If speed is an expensive resource, it is recommended to use this.
This is a fast and near-identical alternative to dplyr::count() using the collapse
package.
Unlike collapse::fcount()
, this works very similarly to dplyr::count()
.
The only main difference is that anything supplied to wt
is recycled and added as a data variable.
Other than that everything works exactly as the dplyr equivalent.
f_count()
and f_add_count()
can be up to >100x faster than the dplyr equivalents.