Skip to content

Instantly share code, notes, and snippets.

@rnfermincota
Created August 12, 2022 14:51
Show Gist options
  • Save rnfermincota/3b0611b780ea27af1389992940ab019a to your computer and use it in GitHub Desktop.
Save rnfermincota/3b0611b780ea27af1389992940ab019a to your computer and use it in GitHub Desktop.
# Libraries
library(f1db)
library(stringr)
#-----------------------------------------------------------
# Database initialization & connection
con <- f1db_connect()
f1db_collect_tables(con)
# Joins & column selection
race_results <-
drivers %>%
left_join(results, by = c("driverId" = "driverId")) %>%
left_join(races, by = c("raceId" = "raceId")) %>%
mutate(driver = paste0(forename, " ", surname)) %>%
select(date, name, driver, grid, positionOrder)
#-----------------------------------------------------------
# List of current drivers in 2022
current_drivers <-
race_results %>%
filter(date %>% str_starts("2022")) %>%
select(driver) %>%
distinct()
# Results
race_results %>%
filter(driver %in% current_drivers[[1]]) %>%
filter(positionOrder == 1) %>%
arrange(desc(grid)) %>%
head(1)
# A tibble: 1 × 5
# date name driver grid positionOrder
# <chr> <chr> <chr> <int> <int>
# 1 2008-09-28 Singapore Grand Prix Fernando Alonso 15 1
#-----------------------------------------------------------
# List of current drivers 1950 to today
current_drivers <-
race_results %>%
select(driver) %>%
distinct()
# Results
race_results %>%
filter(driver %in% current_drivers[[1]]) %>%
filter(positionOrder == 1) %>%
arrange(desc(grid)) %>%
head(1)
# A tibble: 1 × 5
# date name driver grid positionOrder
# <chr> <chr> <chr> <int> <int>
# 1 1983-03-27 United States Grand Prix West John Watson 22 1
#-----------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment