count.: Count observations by group

Description Usage Arguments Examples

View source: R/count.R

Description

Returns row counts of the dataset. If bare column names are provided, count.() returns counts by group.

Usage

1
count.(.df, ..., wt = NULL, sort = FALSE, name = NULL)

Arguments

.df

A data.frame or data.table

...

Columns to group by. tidyselect compatible.

wt

Frequency weights. tidyselect compatible. Can be NULL or a variable:

  • If NULL (the default), counts the number of rows in each group.

  • If a variable, computes sum(wt) for each group.

sort

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

name

The name of the new column in the output.

If omitted, it will default to N.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
test_df <- data.table(
  x = 1:3,
  y = 4:6,
  z = c("a", "a", "b")
)

test_df %>%
  count.()

test_df %>%
  count.(z)

test_df %>%
  count.(where(is.character))

test_df %>%
  count.(z, wt = y, name = "y_sum")

test_df %>%
  count.(z, sort = TRUE)

mtfairbanks/gdt documentation built on May 4, 2021, 9:44 a.m.