fcount {timeplyr} | R Documentation |
A fast replacement to dplyr::count()
Description
Near-identical alternative to dplyr::count()
.
Usage
fcount(
data,
...,
wt = NULL,
sort = FALSE,
order = df_group_by_order_default(data),
name = NULL,
.by = NULL,
.cols = NULL
)
fadd_count(
data,
...,
wt = NULL,
sort = FALSE,
order = df_group_by_order_default(data),
name = NULL,
.by = NULL,
.cols = NULL
)
Arguments
data |
A data frame. |
... |
Variables to group by. |
wt |
Frequency weights.
Can be
|
sort |
If |
order |
Should the groups be calculated as ordered groups?
If |
name |
The name of the new column in the output.
If there's already a column called |
.by |
(Optional). A selection of columns to group by for this operation. Columns are specified using tidy-select. |
.cols |
(Optional) alternative to |
Details
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.
fcount()
and fadd_count()
can be up to >100x faster than the dplyr equivalents.
Value
A data.frame
of frequency counts by group.
Examples
library(timeplyr)
library(dplyr)
iris %>%
fcount()
iris %>%
fadd_count(name = "count") %>%
fslice_head(n = 10)
iris %>%
group_by(Species) %>%
fcount()
iris %>%
fcount(Species)
iris %>%
fcount(across(where(is.numeric), mean))
### Sorting behaviour
# Sorted by group
starwars %>%
fcount(hair_color)
# Sorted by frequency
starwars %>%
fcount(hair_color, sort = TRUE)
# Groups sorted by order of first appearance (faster)
starwars %>%
fcount(hair_color, order = FALSE)