AE 10: Iterating in R

Application exercise
Modified

September 24, 2025

Packages

We will use the following packages in this application exercise.

  • {tidyverse}: For data import, wrangling, and visualization.
  • {rvest}: For scraping HTML files.
  • {robotstxt}: For verifying if we can scrape a website.

Part 1: Iterating over columns

Your turn: Write a function that summarizes multiple specified columns of a data frame and calculates their arithmetic mean and standard deviation using across().

# non-iterative approach for a single variable
my_summary <- function(df, summary_var) {
  df |>
    summarize(
      mean = mean({{ summary_var }}, na.rm = TRUE),
      sd = sd({{ summary_var }}, na.rm = TRUE),
      .groups = "drop"
    )
}

# add code here

Part 2: Data scraping

This will be done in the iterate-cornell-review.R R script. Save the resulting data frame in the data folder.