Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

count..html

Count observations by group


Description

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

Usage

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

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)

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.