count2 | R Documentation |
dplyr::count()
with proportion column and default sort = TRUE
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()
.
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)
df |
A data frame. |
... |
Variables to group by. Passed to |
sort |
Passed to |
wt, name |
Optional, passed to |
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). |
vctrs::vec_count()
count2(mtcars, cyl)
count2(mtcars, cyl, sort = FALSE)
vcount(c(1, 2, 2, 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.