Data quality · Statistics Library

Duplicate rows

Duplicate rows are two or more records that are identical (or represent the same underlying unit measured twice), and unless genuinely intended as repeated observations they inflate the sample size and understate uncertainty.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

If the exact same row appears twice in a dataset (same patient, same measurement, same everything), the analysis will treat it as two independent pieces of evidence when it is really only one, counted twice. This makes the results look more certain (smaller standard errors, smaller p-values) than the actual amount of independent information supports.

Duplicates commonly arise from a data-pipeline mistake: a failed script re-running and re-appending the same records, a join that unintentionally multiplies rows, or a form being submitted twice by the same respondent. They are worth investigating specifically, not just silently removing, because the SAME bug that created duplicates may have also corrupted or dropped other rows.

Not every repeated set of values is a mistake, though: a dataset can legitimately contain two different people who happen to share identical recorded values by coincidence. The distinguishing question is whether the duplicate rows represent the same underlying unit (an error) or genuinely distinct units that happen to match (not necessarily an error).

Duplicate rows are also called duplicate records. Removing the extra copies is called deduplication, and it should only be done after checking that the copies really are one event recorded twice. Record linkage is the harder problem of matching rows that describe the same thing but are not spelled identically, such as 'J. Smith' and 'John Smith'. Duplicates usually come from a data pipeline error, such as a file imported twice or a join that matched one row to several.

Practitioner explanation

Exact duplicate detection (all columns identical) is a straightforward hash/sort check; the harder and more consequential case is NEAR-duplicates from record linkage across systems, or PARTIAL duplicates sharing a unique identifier but differing in a few fields (often the more recently updated version of a record), which require a deliberate deduplication rule (keep latest, keep first, or flag for manual review) rather than a blanket drop.

Duplication interacts directly with the independence assumption: a duplicated row is not merely redundant information, it is a violation of the observations-are-independent assumption underlying the effective sample size used by every classical standard error formula, and its effect is structurally identical to unaccounted-for clustering.

KernelStats' EDA report flags the count of exact duplicate rows (n_duplicate_rows) on import, as a data-quality signal alongside missingness and zero-variance columns, so a pipeline artifact is visible before it silently inflates a test's apparent significance.

When to use it

Consider it when

Check for duplicate rows on import and after any join or merge operation, which are the most common sources of accidental duplication.

Use caution when

Do not assume every set of identical rows is an error: confirm whether they represent the same underlying unit recorded twice (a bug) or distinct units that coincidentally match (not necessarily a problem) before deleting anything.

Common misconceptions

Misconception

More rows always means a more reliable analysis.

Correction

Duplicate rows increase the row COUNT without adding new information, which inflates apparent precision (smaller standard errors) without any real gain in the amount of independent evidence.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §2.2 Data quality checks, NIST/SEMATECH (2012), §2.2.