Classwork 6

Data Transformation with R

Author

Byeong-Hak Choe

Published

October 1, 2025

Modified

September 28, 2025

Part 1. filter(), arrange(), and distinct()

For Part 1, consider the nycflights13::flights data.frame.

library(tidyverse)
library(nycflights13)
flights <- flights

For detailed descriptions of the variables in this data frame, load its help documentation using the following command:

# Documentation for the `flights` data.frame from the `nycflights13` package
?flights   # displays the description of variables in the `flights` data.frame

Question 1

  • Find all flights that had an arrival delay of two or more hours.
  • Find all flights that flew to Houston (IAH or HOU).
  • Find all flights that departed in summer (July, August, and September).
  • Find all flights that arrived more than two hours late, but did not leave late.

Answer:



Question 2

  • How many flights have a missing dep_time?

Answer:



Question 3

  • Sort flights to find the most delayed flights.

Answer:



Question 4

  • Was there a flight on every day of 2013?

Answer:



Part 2. select() and rename()

Consider the following data.frame, nyc_payroll_new.

library(tidyverse)
nyc_payroll_new <- read_csv("https://bcdanl.github.io/data/nyc_payroll_2024.csv")


For detailed descriptions of the variables in this data.frame, please refer to the following link:


Question 1

Create a new data.frame, df that keeps only the following five variablesโ€”Fiscal_Year, Agency_Name, First_Name, Last_Name, and Base_Salaryโ€”from the data.frame nyc_payroll_new.

Answer:



Question 2

Given the data.frame df with a variable named Agency_Name, how would you rename it to Agency?

Answer:



Question 3

How would you remove the Fiscal_Year variable using select()?

Answer:



Discussion

Welcome to our Classwork 6 Discussion Board! ๐Ÿ‘‹

This space is designed for you to engage with your classmates about the material covered in Classwork 6.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) or peer classmate (@GitHub-Username) regarding the Classwork 6 materials or need clarification on any points, donโ€™t hesitate to ask here.

Letโ€™s collaborate and learn from each other!

Back to top