add_tally.: Add a count column to the data frame

View source: R/add_count.R

add_tally.R Documentation

Add a count column to the data frame

Description

Add a count column to the data frame.

df %>% add_count(a, b) is equivalent to using df %>% mutate(n = n(), .by = c(a, b))

Usage

add_tally.(.df, wt = NULL, sort = FALSE, name = NULL)

Arguments

.df

A data.frame or data.table

wt

Frequency weights. 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

df <- data.table(
  a = c("a", "a", "b"),
  b = 1:3
)

df %>%
  add_count(a)

tidytable documentation built on Oct. 5, 2023, 5:07 p.m.