duplicate_count: Count duplicate values

View source: R/duplicate-count.R

duplicate_countR Documentation

Count duplicate values

Description

duplicate_count() returns a frequency table of the values in a vector or data frame. For a data frame, it pools the values of all columns and records which columns each value appears in.

This is a blunt tool for initial checks. If many values have few characters each, duplicates occur by chance and mean little.

Call audit() on the output for summary statistics.

Usage

duplicate_count(x, ignore = NULL, locations_type = c("character", "list"))

Arguments

x

Vector, matrix, or data frame. Missing values are not counted, nor are blank strings, "NA", and "NaN", which count as missing.

ignore

Optionally, a vector of values not to count.

locations_type

String. "character" (the default) pastes the column names in locations into one string; "list" keeps them as a vector per value, which is better for programming.

Value

A tibble with these columns, or only the first two if x is not named:

  • value: the distinct values of x.

  • frequency: how often each occurs, in descending order.

  • locations: the names of the columns of x in which value appears.

  • locations_n: the number of such columns.

The tibble has the class scrutiny_dup_count, which is recognized by audit().

Summaries with audit()

audit() on duplicate_count() output returns summary statistics for frequency and locations_n (or frequency alone if x is not named).

See Also

  • duplicate_count_colpair() for duplicates between pairs of columns.

  • duplicate_tally() for counts next to each value.

  • janitor::get_dupes() for duplicate rows.

Examples

iris |>
  duplicate_count()

iris |>
  duplicate_count() |>
  audit()

# Ignore some values:
iris |>
  duplicate_count(ignore = c("setosa", "versicolor", "virginica"))

scrutiny documentation built on Nov. 11, 2026, 1:09 a.m.