liveBook · Manning

Read_csv

As explained in Statistics Slam Dunk

The read_csv() function is a readr function that reads comma-separated-values data into an R data structure.

`read_csv()` imports a comma-separated-values file into an R data object. It comes from the `readr` package, part of the tidyverse, and is the starting point for examining, cleaning, visualizing, and analyzing NBA data. section 1.3 section 2.2

Give `read_csv()` a quoted filename or file path, then assign the imported data to an object with `<-`. If the file is in the current working directory, its filename and `.csv` extension are enough; otherwise, provide its location or select it interactively with `file.choose()`. A file outside the working directory will not load when only its filename is supplied. section 2.2 section 5.2

draft <- read_csv("draft.csv")

This minimal call imports draft-pick data and stores it in an object named `draft`. section 2.2

A practical import-and-check routine is:

  • Load `readr` before calling `read_csv()`, after installing the package if needed. section 1.3
  • Import each CSV into a clearly named object; multiple files require multiple calls. section 6.2 section 14.2.4
  • Confirm the row and column counts with `dim()` immediately after importing. section 2.2 section 9.2
  • Inspect variables and a compact data preview with `glimpse()` before wrangling. section 3.3 section 8.3

Checking a large play-by-play import

A 2019–20 play-by-play CSV is imported as `pbp`, then inspected with `glimpse()`. The preview reports 543,149 rows and 44 columns, while displaying variable names, inferred types, and sample values. Large files may take several seconds to load on a personal computer; inspect them before selecting, filtering, or converting variables. section 8.3 section 16.2

Importing is not the analysis. Raw files can include unneeded columns, missing values, duplicated records, or formats that do not fit the question. After loading, narrow the data, create needed variables, reshape or join data sets, and validate each important transformation before modeling or statistical testing. section 14.2 section 12.3

How Statistics Slam Dunk covers it

How deep it goes
Explains filenames, paths, working directories, interactive selection, and dimension checks, then defers data preparation to later wrangling.
Examples
Uses draft picks, box scores, salaries, team records, and 543,149-row play-by-play data as imported CSV artifacts.
What it assumes
Assumes an installed and loaded readr package while teaching CSV filenames, file locations, and working-directory behavior.
What you can do after
Apply it via readr to import a CSV by filename, file path, or interactive selection and verify its dimensions.
How it connects
Connects CSV import with readr, tidyverse, working directories, dim(), glimpse(), dplyr, and data wrangling.

Also explained in

Compare how 5 books explain read_csv →

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.