Read + transform · Week 06

Reading and Transforming Data with R

Bring a CSV into R, inspect its rows and columns, and use dplyr to keep, sort, and select the data needed for a question.

Sep 28–Oct 2Lecture 5 + Classwork 5
ImportantWeek 6 sequence
  1. Use Lecture 5 to read a CSV from a project folder or web address and inspect the resulting data frame.
  2. Use Classwork 5 to find and copy an absolute pathname for a downloaded file.
  3. Practice the lecture’s dplyr transformations with filter(), arrange(), distinct(), and select().

Focus

  • CSV files and absolute versus relative paths
  • Rows, columns, observations, and variables
  • Filtering, sorting, and selecting with dplyr

Prepare

  • Open Lecture 5 and Classwork 5
  • Open your section’s project in Posit Cloud
  • Download the lecture’s CSV from Brightspace

Practice

  • Read a CSV with read_csv() and inspect its data frame
  • Find and copy a downloaded file’s pathname
  • Use dplyr verbs to transform a data frame

Learning targets

  • Explain what a CSV stores and how an absolute or relative pathname locates a file.
  • Use read_csv() to import a CSV from a project folder or web address.
  • Inspect a data frame’s dimensions, variable names, and values.
  • Use filter(), arrange(), distinct(), and select() to transform a data frame.
  • Recognize missing values and check them with is.na().

From a file to a useful data frame

Concept Plain-language meaning
CSV A plain-text table with values separated by commas.
Pathname The location of a file, written as an absolute or relative path.
Data frame A table in R with observations in rows and variables in columns.
dplyr verb A function that changes which rows or columns appear, or their order.
Tip

In Posit Cloud, put custdata_rev.csv in a data folder inside your project. Then data/custdata_rev.csv is a relative pathname from the project folder.

Core pattern

custdata <- readr::read_csv("data/custdata_rev.csv")
dplyr::glimpse(custdata)

Lecture slides

TipLecture slide shortcuts

Click inside the slide preview, then use:

  • the visible ←/→ controls to page through the slides;
  • your mouse wheel or trackpad to keep scrolling the weekly page;
  • M to open the menu;
  • F to enter fullscreen;
  • E to enter or exit PDF export mode;
  • Ctrl + Shift + F to search within the slides;
  • Esc to exit the menu or fullscreen; and
  • T to switch between dark and light mode.
Lecture 5 · Reading and Transforming Data with RView slides in new tab

This week’s materials

Back to top