## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.width = 7, fig.height = 4.2 ) ## ----setup-------------------------------------------------------------------- library(olympicAthletes) ## ----athletes-glimpse--------------------------------------------------------- data(olympic_athletes) str(olympic_athletes, give.attr = FALSE, vec.len = 2) ## ----athletes-by-year--------------------------------------------------------- tab <- table(olympic_athletes$year, olympic_athletes$season) tail(tab, 10) ## ----medal-per-player--------------------------------------------------------- # Every roster member of the men's ice hockey gold medal team # at Beijing 2022 gets a Gold row: hockey_2022 <- subset( olympic_athletes, year == 2022 & event == "Ice Hockey Men's Ice Hockey" & medal == "Gold" ) nrow(hockey_2022) ## ----medal-table-------------------------------------------------------------- data(medal_table) head(subset(medal_table, year == 2024), 5) ## ----paris-top---------------------------------------------------------------- paris <- subset(medal_table, year == 2024) paris <- paris[order(-paris$gold, -paris$total), ] head(paris[, c("noc", "country", "gold", "silver", "bronze", "total")], 5) ## ----editions----------------------------------------------------------------- data(editions) head(editions[, c("games", "city_local_latin", "city_english", "country", "opening_ceremony", "closing_ceremony", "participants", "medal_events")], 10)