A wrapper around dplyr::count() with sort set to TRUE by default and the an additional column created by default containing the proportional fraction each observation makes of the whole.

count2(x, ..., wt = NULL, sort = TRUE, prop = TRUE, sum = NULL)

count_vec(x, sort = TRUE, prop = TRUE, sum = NULL)

Arguments

x

A data frame.

...

Variables to group by.

wt

Frequency weights.

sort

If TRUE, will show the largest groups at the top.

prop

If TRUE, compute the fraction of marginal table.

sum

Column to replace with a cumulative sum (n, p, or np).

Value

A tibble of element counts

Examples

count2(iris, Species)
#> # A tibble: 3 × 3
#>   Species        n     p
#>   <fct>      <int> <dbl>
#> 1 setosa        50 0.333
#> 2 versicolor    50 0.333
#> 3 virginica     50 0.333