Learn R Programming

scrutiny (version 1.0.0)

duplicate_tally: Count duplicates at each observation

Description

For every value in a vector or data frame, duplicate_tally() counts how often it occurs in the whole input, and reports the count next to the value.

Call audit() on the output for summary statistics.

Usage

duplicate_tally(x, ignore = NULL, colname_end = "n")

Value

A tibble with the columns of x (a value column if x is a vector), each followed by its tally column. It has the class scrutiny_dup_tally, which is recognized by audit().

Arguments

x

Vector, matrix, or data frame. Blank strings, "NA", and "NaN" count as missing.

ignore

Optionally, a vector of values not to check. Their tally is NA, as is that of missing values.

colname_end

String. Suffix of the tally columns. Default is "n".

Summaries with <code>audit()</code>

audit() on duplicate_tally() output returns summary statistics for each tally column, with a .total row across all of them. It finds these columns by the names that duplicate_tally() gave them, so a renamed one is left out.

Details

Values with few characters are often duplicated by chance: in iris, 99% of values have a duplicate. Duplicates are more meaningful when there are fewer values and they have more characters.

Values are compared and returned as strings, so 1 and "1" are duplicates, but 2 and "2.0" are not: 2.0 becomes "2".

See Also

  • duplicate_count() for a frequency table.

  • duplicate_count_colpair() for duplicates between pairs of columns.

  • janitor::get_dupes() for duplicate rows.

Examples

Run this code
duplicate_tally(x = pigs4)

duplicate_tally(x = pigs4$snout)

pigs4 |>
  duplicate_tally() |>
  audit()

pigs4 |>
  duplicate_tally(ignore = c(8.13, 7.57))

Run the code above in your browser using DataLab