count2: 'dplyr::count()' with proportion column and default 'sort =...

View source: R/count.R

count2R Documentation

dplyr::count() with proportion column and default sort = TRUE

Description

Adds a column which gives the proportion of total rows in that group.

  • vcount() is similar but works with a vector input.

  • countp() and countv() are alternative names for, respectively, count2() and vcount().

Usage

count2(df, ..., sort = TRUE, wt = NULL, name = NULL, pname = NULL)

countp(df, ..., sort = TRUE, wt = NULL, name = NULL, pname = NULL)

vcount(x, sort = TRUE, name = NULL, pname = NULL)

countv(x, sort = TRUE, name = NULL, pname = NULL)

Arguments

df

A data frame.

...

Variables to group by. Passed to count().

sort

Passed to count, but defaults to TRUE.

wt, name

Optional, passed to count.

pname

Name for the proportion column. If omitted, it will default to p. If there's already a column called p, it will use pp. If there's a column called p and pp, it'll use ppp, and so on, adding ps until it gets a new name.

x

A vector (including a data frame).

See Also

vctrs::vec_count()

Examples

count2(mtcars, cyl)
count2(mtcars, cyl, sort = FALSE)
vcount(c(1, 2, 2, 3))


jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.