count: Count observations by group

View source: R/count.R

countR Documentation

Count observations by group

Description

Analogous function for count and add_count in dplyr.

Usage

count(.data, ..., sort = FALSE, name = "n")

add_count(.data, ..., name = "n")

Arguments

.data

data.table

...

variables to group by.

sort

logical. If TRUE result will be sorted in desending order by resulting variable.

name

character. Name of resulting variable. Default uses "n".

Value

data.table

Examples

a = as.data.table(mtcars)
count(a,cyl)
count(a,cyl,sort = TRUE)
a

b = as.data.table(iris)
b %>% add_count(Species,name = "N")
b

tidyft documentation built on Jan. 9, 2023, 1:27 a.m.