library(tidyverse)
::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE) knitr
Homework 3
homework_3
nfl_2019
library(readr)
<- read_csv("_data/nfl2019.csv")
nfl View(nfl)
<- read_csv("_data/nfl2019.csv",
nfl skip = 1,
col_names = c("delete", "Opponent", "Home_Ranking", "Opponent_Ranking", "Home_1st_Downs", "Home_Total_Yards", "Home_Passing_Yards", "Home_Rushing_Yards", "Home_Turnovers", "Opponent_1st_Downs", "Opponent_Total_Yards","Opponent_Passing_Yards", "Opponent_Rushing_Yards", "Opponent_Turnovers", "Home_Offensive_Ranking", "Home_Defensive_Ranking", "Home_Special_Teams", "Home", "Year", "Winner")) %>%
select(!starts_with("delete")) %>%
na_if("Skipped")
mean(nfl$Home_Total_Yards)
[1] 348.048
mean(nfl$Opponent_Total_Yards)
[1] 346.2134
mean(nfl$Home_Passing_Yards)
[1] 231.8302
mean(nfl$Opponent_Passing_Yards)
[1] 230.5542
mean(nfl$Home_Rushing_Yards)
[1] 116.2179
mean(nfl$Opponent_Rushing_Yards)
[1] 115.6592
%>%
nflggplot(aes(x=`Home_Passing_Yards`, y=`Year`)) +
geom_point()
%>%
nflggplot(aes(x=`Opponent_Passing_Yards`, y=`Year`)) +
geom_point()
$home_winner <- with(nfl, ifelse(Home == Winner, 'Win', 'Loss'))
nfl
view(nfl)
nrow(filter(nfl,home_winner == "Win"))
[1] 451
sum(nfl$Home_Passing_Yards > nfl$Opponent_Passing_Yards & nfl$home_winner == "Win")
[1] 262
sum(nfl$Home_Rushing_Yards > nfl$Opponent_Rushing_Yards & nfl$home_winner == "Win")
[1] 311
library(ggplot2)
<- nfl %>%
scatter ggplot(mapping=aes(x = Year, y = `Home_Passing_Yards`))+
geom_point(aes(color=home_winner))
scatter
library(ggplot2)
<- nfl %>%
scatter ggplot(mapping=aes(x = Year, y = `Home_Rushing_Yards`))+
geom_point(aes(color=home_winner))
scatter