data(cars)
Question 1
median(cars$speed)
## [1] 15
Question 2
library(jsonlite)
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100"
btc_data <- fromJSON(url)
btc_df <- btc_data$Data$Data
max_close <- max(btc_df$close, na.rm = TRUE)
max_close
## [1] 124723
Question 3 (Mini Project)
Research Qs:
1. Which NFC teams had the highest win percentages in 2020?
2. Is there a relationship between points scored per game and total
wins?
3. Which NFC teams allowed the fewest points per game?
Data Cleaning
str(team_stats)
## tibble [20 × 13] (S3: tbl_df/tbl/data.frame)
## $ Tm : chr [1:20] "NFC East" "Washington Football Team*" "New York Giants" "Dallas Cowboys" ...
## $ W : chr [1:20] "NFC East" "7" "6" "6" ...
## $ L : chr [1:20] "NFC East" "9" "10" "10" ...
## $ T : chr [1:20] "NFC East" "0" "0" "0" ...
## $ W-L%: chr [1:20] "NFC East" ".438" ".375" ".375" ...
## $ PF : chr [1:20] "NFC East" "335" "280" "395" ...
## $ PA : chr [1:20] "NFC East" "329" "357" "473" ...
## $ PD : chr [1:20] "NFC East" "6" "-77" "-78" ...
## $ MoV : chr [1:20] "NFC East" "0.4" "-4.8" "-4.9" ...
## $ SoS : chr [1:20] "NFC East" "-1.2" "0.4" "-0.2" ...
## $ SRS : chr [1:20] "NFC East" "-0.8" "-4.4" "-5.1" ...
## $ OSRS: chr [1:20] "NFC East" "-4.1" "-6.7" "1.0" ...
## $ DSRS: chr [1:20] "NFC East" "3.2" "2.3" "-6.1" ...
names(team_stats) <- make.names(names(team_stats))
head(team_stats)
## # A tibble: 6 × 13
## Tm W L T W.L. PF PA PD MoV SoS SRS OSRS DSRS
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 NFC E… NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC …
## 2 Washi… 7 9 0 .438 335 329 6 0.4 -1.2 -0.8 -4.1 3.2
## 3 New Y… 6 10 0 .375 280 357 -77 -4.8 0.4 -4.4 -6.7 2.3
## 4 Dalla… 6 10 0 .375 395 473 -78 -4.9 -0.2 -5.1 1.0 -6.1
## 5 Phila… 4 11 1 .281 334 418 -84 -5.3 0.8 -4.4 -2.8 -1.6
## 6 NFC N… NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC … NFC …
team_stats$W <- as.numeric(team_stats$W)
## Warning: NAs introduced by coercion
team_stats_clean <- team_stats[!is.na(team_stats$W), ]
head(team_stats_clean)
## # A tibble: 6 × 13
## Tm W L T W.L. PF PA PD MoV SoS SRS OSRS DSRS
## <chr> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Washi… 7 9 0 .438 335 329 6 0.4 -1.2 -0.8 -4.1 3.2
## 2 New Y… 6 10 0 .375 280 357 -77 -4.8 0.4 -4.4 -6.7 2.3
## 3 Dalla… 6 10 0 .375 395 473 -78 -4.9 -0.2 -5.1 1.0 -6.1
## 4 Phila… 4 11 1 .281 334 418 -84 -5.3 0.8 -4.4 -2.8 -1.6
## 5 Green… 13 3 0 .813 509 369 140 8.8 -1.1 7.7 5.9 1.8
## 6 Chica… 8 8 0 .500 372 370 2 0.1 0.1 0.2 -2.2 2.4
Research Qs
1. Which NFC teams had the highest win percentages in 2020?
top_win_pct <- team_stats_clean[order(team_stats_clean$W.L., decreasing = TRUE), ]
head(top_win_pct)
## # A tibble: 6 × 13
## Tm W L T W.L. PF PA PD MoV SoS SRS OSRS DSRS
## <chr> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Green… 13 3 0 .813 509 369 140 8.8 -1.1 7.7 5.9 1.8
## 2 New O… 12 4 0 .750 482 337 145 9.1 0.5 9.6 5.1 4.5
## 3 Seatt… 12 4 0 .750 459 371 88 5.5 0.0 5.5 4.8 0.7
## 4 Tampa… 11 5 0 .688 492 355 137 8.6 0.8 9.4 6.5 2.8
## 5 Los A… 10 6 0 .625 372 296 76 4.8 0.7 5.4 -0.8 6.2
## 6 Chica… 8 8 0 .500 372 370 2 0.1 0.1 0.2 -2.2 2.4
2. Is there a relationship between points scored per game and total
wins?
team_stats_clean$PF <- as.numeric(team_stats_clean$PF)
plot(team_stats_clean$PF, team_stats_clean$W,
xlab = "Points Scored (PF)",
ylab = "Wins",
main = "Points Scored vs Wins",
pch = 19, col = "darkgreen")
abline(lm(W ~ PF, data = team_stats_clean), col = "red")

cor(team_stats_clean$PF, team_stats_clean$W)
## [1] 0.7642514
Yes there is a strong postive correlation and relationship between
ppg and total wins
3. Which NFC teams allowed the fewest points per game?
team_stats_clean$PA <- as.numeric(team_stats_clean$PA)
best_defense <- team_stats_clean[order(team_stats_clean$PA), ]
best_defense[, c("Tm", "PA", "W", "L")][1:5, ]
## # A tibble: 5 × 4
## Tm PA W L
## <chr> <dbl> <dbl> <chr>
## 1 Los Angeles Rams+ 296 10 6
## 2 Washington Football Team* 329 7 9
## 3 New Orleans Saints* 337 12 4
## 4 Tampa Bay Buccaneers+ 355 11 5
## 5 New York Giants 357 6 10