liveBook · Manning

Distinct keyword

As explained in Statistics Slam Dunk

The distinct() function from dplyr returns rows containing unique combinations of selected columns from a tabular object.

Use dplyr's distinct() to keep one row for each unique combination of selected columns. In NBA data, checking Year, Player, and Pos exposes repeated player-season-position combinations created by multi-team records and total rows. section 19.3.1

Check duplicate player combinations

dat1 %>% distinct(Year, Player, Pos) -> test1 dim(test1) ## [1] 12239 3 The result contains 12,239 unique combinations, 2,181 fewer observations than dat1. This identifies duplicate combinations; it does not add their statistics together. Aggregation can follow separately with group_by() and summarize(). section 19.3.1

Use distinct() to:

  • Select unique records across one or several columns. section 19.5
  • Inspect whether apparent duplicates represent total rows or repeated records before standardizing the data. section 19.3.1

How Statistics Slam Dunk covers it

How deep it goes
Demonstrates selected-column deduplication and record counting, then defers statistical aggregation to group_by() and summarize().
Examples
Uses dat1 and the Year, Player, Pos columns to count 12,239 unique combinations amid NBA multi-team records.
What it assumes
Assumes a tabular object and basic dplyr piping, while demonstrating column-based uniqueness with concrete NBA data.
What you can do after
Apply it via dplyr to inspect unique combinations before deciding how to remove or aggregate duplicate records.
How it connects
Connects distinct() with data standardization, filter(), tally(), group_by(), summarize(), and comparedf().

Also explained in

Compare how 4 books explain distinct keyword →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.