A dataset is a collection of recorded observations arranged as variables and records for analysis. It may arrive as a CSV file or spreadsheet, and its dimensions describe its rows and columns. Real datasets rarely arrive ready for the question at hand: they can include irrelevant fields, unwanted records, or variables that must be created or converted. section 13.2 section 17.2
Treat preparation as part of the analysis, not a preliminary nuisance. Import the data, inspect its size and variables, then reduce it to the records and columns needed. Filtering, selecting, renaming, changing variable classes, reshaping, and joining can turn a broad raw dataset into an object suited to visualization or statistical testing. section 2.7 section 16.2
Useful questions to ask of any dataset include:
- What does one record represent? A player-season-team dataset can assign one unique record to each player/year/team combination. section 13.2
- Which variables answer the analytical question, and which can be removed? Reducing width keeps queries faster and attention focused. section 13.2
- Which observations belong in scope? Filter by season, venue, event type, team, or other logical criteria before computing results. section 7.3 section 19.2
- Do related datasets need to be combined? Separate road and home records can be aligned into one dataset for comparison. section 7.3
From game logs to a focused comparison
To compare high-performing teams by quarter, start with game data, filter to six road teams, retain relevant quarter outcomes, count the outcome categories, and calculate percentages. A small new data frame can then hold one percentage per quarter for a bar chart. The transformed dataset makes the comparison visible without claiming that the original raw layout was already fit for it. section 6.4.5
nbadf3 %>%
filter(teamR == "Milwaukee" | teamR == "Toronto" |
teamR == "Boston" | teamR == "Denver" |
teamR == "Houston" | teamR == "LA Clippers") -> nbadf7
nbadf7 %>%
filter(Q1vF == "RR" | Q1vF == "RH") -> nbadf8
This filter creates a focused dataset by retaining observations for six named road teams before later analysis. section 6.4.5























