#Question 1
data(cars)
median(cars$speed)
## [1] 15
#Question 2
#install.packages("jsonlite")
library(jsonlite)
BTC <- fromJSON("https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100")
BTC_Data <- BTC$Data$Data
BTC_Data
## time high low open volumefrom volumeto close
## 1 1750636800 106134.1 99685.07 101015.4 35198.88 3606601777 105423.7
## 2 1750723200 106358.8 104710.65 105423.7 19908.29 2099787247 106133.2
## 3 1750809600 108196.8 105880.48 106133.2 19838.91 2128340952 107399.9
## 4 1750896000 108330.6 106605.50 107399.9 14664.25 1575810933 107012.2
## 5 1750982400 107794.0 106421.82 107012.2 16821.31 1799885723 107105.2
## 6 1751068800 107591.5 106884.15 107105.2 3472.45 372614445 107346.4
## 7 1751155200 108538.4 107233.58 107346.4 6094.35 657403121 108391.9
## 8 1751241600 108815.7 106756.38 108391.9 14220.51 1530756559 107169.8
## 9 1751328000 107574.1 105295.02 107169.8 15730.48 1673173145 105724.2
## 10 1751414400 109818.5 105143.10 105724.2 19611.45 2124516059 108886.6
## 11 1751500800 110584.4 108579.56 108886.6 16647.63 1825182142 109639.0
## 12 1751587200 109810.0 107283.92 109639.0 10440.09 1130647601 108027.7
## 13 1751673600 108444.7 107798.16 108027.7 3465.16 374668092 108244.5
## 14 1751760000 109729.0 107846.02 108244.5 5651.56 614763573 109233.9
## 15 1751846400 109737.8 107513.97 109233.9 13350.41 1447160434 108277.2
## 16 1751932800 109248.3 107445.04 108277.2 12122.12 1316408875 108955.1
## 17 1752019200 112077.2 108341.92 108955.1 19761.34 2177951433 111291.7
## 18 1752105600 116848.3 110555.52 111291.7 31905.27 3616719328 116023.3
## 19 1752192000 118890.3 115236.69 116023.3 26050.27 3060911543 117573.9
## 20 1752278400 118240.0 116954.09 117573.9 7395.67 869899617 117468.2
## 21 1752364800 119503.6 117264.60 117468.2 9553.52 1133368268 119127.7
## 22 1752451200 123220.3 118951.55 119127.7 31361.70 3784774921 119869.0
## 23 1752537600 119958.9 115709.64 119869.0 50123.19 5881848281 117777.9
## 24 1752624000 120122.2 117043.92 117777.9 27837.68 3310853210 118700.4
## 25 1752710400 121020.9 117485.98 118700.4 25218.52 3000532789 119282.7
## 26 1752796800 120911.2 116902.92 119282.7 26111.51 3096339405 118025.9
## 27 1752883200 118572.5 117339.41 118025.9 6706.12 791893577 117913.3
## 28 1752969600 118903.9 116533.22 117913.3 9166.19 1081488186 117328.6
## 29 1753056000 119712.2 116581.70 117328.6 18543.72 2187836281 117441.8
## 30 1753142400 120298.6 116186.23 117441.8 21981.53 2607540535 120023.5
## 31 1753228800 120167.5 117361.89 120023.5 17163.70 2029832616 118808.8
## 32 1753315200 119555.9 117214.42 118808.8 17930.71 2128340081 118397.3
## 33 1753401600 118523.3 114756.37 118397.3 47767.94 5546818212 117644.1
## 34 1753488000 118355.1 117143.68 117644.1 10959.83 1291296799 117971.3
## 35 1753574400 119808.3 117872.15 117971.3 10341.68 1228024808 119468.7
## 36 1753660800 119835.4 117403.28 119468.7 18092.60 2142740462 118059.9
## 37 1753747200 119286.0 116933.73 118059.9 17580.06 2073820445 117942.1
## 38 1753833600 118800.1 115769.47 117942.1 18335.33 2153325010 117853.3
## 39 1753920000 118927.1 115493.77 117853.3 16934.89 1991848800 115765.4
## 40 1754006400 116060.7 112682.82 115765.4 33588.86 3851719229 113263.5
## 41 1754092800 114034.0 112006.36 113263.5 12452.57 1407609649 112546.3
## 42 1754179200 114803.5 111925.95 112546.3 8326.85 947196437 114238.8
## 43 1754265600 115744.6 114140.41 114238.8 14470.62 1662390457 115065.9
## 44 1754352000 115111.4 112629.49 115065.9 16922.91 1925704360 114127.6
## 45 1754438400 115748.2 113364.73 114127.6 14480.66 1659630183 115038.4
## 46 1754524800 117690.9 114288.63 115038.4 16359.62 1904030479 117522.3
## 47 1754611200 117698.4 115895.35 117522.3 14582.39 1702088353 116692.9
## 48 1754697600 117940.3 116360.05 116692.9 7930.51 926558904 116501.3
## 49 1754784000 119320.8 116496.35 116501.3 10554.12 1248946431 119311.7
## 50 1754870400 122309.7 118106.91 119311.7 25659.91 3086540255 118714.6
## 51 1754956800 120326.0 118214.28 118714.6 18213.63 2172908090 120128.2
## 52 1755043200 123735.4 118948.18 120128.2 27352.96 3321096940 123374.6
## 53 1755129600 124532.7 117241.12 123374.6 35491.88 4249355542 118391.6
## 54 1755216000 119335.9 116865.92 118391.6 19724.55 2327158152 117440.1
## 55 1755302400 118000.6 117242.73 117440.1 6405.98 753827490 117469.5
## 56 1755388800 118639.8 117268.69 117469.5 6706.31 791200442 117488.0
## 57 1755475200 117627.7 114716.49 117488.0 22732.79 2634618668 116292.1
## 58 1755561600 116789.9 112738.04 116292.1 26286.85 3006851750 112870.7
## 59 1755648000 114642.3 112387.14 112870.7 22978.24 2610717314 114291.4
## 60 1755734400 114816.8 111993.84 114291.4 19947.31 2256735255 112491.8
## 61 1755820800 117428.1 111675.14 112491.8 28375.72 3261042644 116909.8
## 62 1755907200 117003.3 114533.54 116909.8 8271.23 955311764 115391.8
## 63 1755993600 115626.3 110860.71 115391.8 17025.82 1932434686 113486.7
## 64 1756080000 113648.6 109292.22 113486.7 33305.33 3708998747 110150.1
## 65 1756166400 112407.5 108701.29 110150.1 27215.82 2999152225 111805.9
## 66 1756252800 112669.1 110381.63 111805.9 21850.84 2440706984 111277.0
## 67 1756339200 113487.6 110887.39 111277.0 16865.13 1898278606 112582.2
## 68 1756425600 112646.7 107512.41 112582.2 29122.98 3185827655 108393.1
## 69 1756512000 108937.2 107381.29 108393.1 9682.99 1049906248 108833.5
## 70 1756598400 109510.2 108095.95 108833.5 9099.54 990157825 108273.7
## 71 1756684800 109913.3 107271.39 108273.7 21783.85 2365084072 109256.3
## 72 1756771200 111796.2 108420.77 109256.3 27112.92 2993969176 111245.9
## 73 1756857600 112601.7 110556.54 111245.9 19087.45 2132239040 111751.5
## 74 1756944000 112225.9 109345.22 111751.5 19577.20 2162838408 110732.3
## 75 1757030400 113400.4 110217.27 110732.3 28328.28 3163045481 110677.0
## 76 1757116800 111320.3 110019.89 110677.0 6640.60 734143439 110230.2
## 77 1757203200 111607.9 110215.70 110230.2 6492.41 720954382 111143.2
## 78 1757289600 112937.8 110628.16 111143.2 16345.84 1829788896 112089.1
## 79 1757376000 113293.1 110777.59 112089.1 18844.58 2108163610 111549.1
## 80 1757462400 114341.9 110940.58 111549.1 23523.08 2661952162 113988.2
## 81 1757548800 115543.7 113457.52 113988.2 18345.68 2096575533 115537.8
## 82 1757635200 116816.5 114785.30 115537.8 20842.83 2412089976 116116.3
## 83 1757721600 116361.1 115207.42 116116.3 7083.57 820638135 115971.9
## 84 1757808000 116227.4 115203.80 115971.9 7290.45 843593558 115351.9
## 85 1757894400 116808.1 114427.70 115351.9 18559.61 2137738674 115401.1
## 86 1757980800 117006.6 114765.74 115401.1 16305.16 1890323068 116838.3
## 87 1758067200 117331.1 114742.84 116838.3 23702.53 2750924038 116488.2
## 88 1758153600 117981.1 116134.78 116488.2 19195.15 2253362090 117126.5
## 89 1758240000 117511.0 115150.85 117126.5 16753.48 1947524484 115702.0
## 90 1758326400 116202.3 115488.37 115702.0 5995.45 694697640 115756.1
## 91 1758412800 115901.0 115262.90 115756.1 5422.99 626782372 115299.8
## 92 1758499200 115439.0 112027.44 115299.8 28253.02 3197786130 112747.9
## 93 1758585600 113372.6 111518.32 112747.9 18488.69 2080069064 112043.7
## 94 1758672000 114013.4 111118.70 112043.7 17597.56 1988342352 113360.7
## 95 1758758400 113559.7 108664.26 113360.7 34940.33 3874673082 109061.1
## 96 1758844800 110387.3 108695.14 109061.1 27943.91 3057709370 109723.9
## 97 1758931200 109822.4 109156.33 109723.9 7105.98 778286679 109727.4
## 98 1759017600 112407.0 109280.14 109727.4 11935.68 1316899924 112226.6
## 99 1759104000 114496.6 111625.37 112226.6 19529.19 2209223704 114407.1
## 100 1759190400 114866.5 112727.79 114407.1 22976.41 2612642607 114078.2
## 101 1759276800 118280.4 114004.91 114078.2 26465.07 3077727772 117730.3
## conversionType conversionSymbol
## 1 direct
## 2 direct
## 3 direct
## 4 direct
## 5 direct
## 6 direct
## 7 direct
## 8 direct
## 9 direct
## 10 direct
## 11 direct
## 12 direct
## 13 direct
## 14 direct
## 15 direct
## 16 direct
## 17 direct
## 18 direct
## 19 direct
## 20 direct
## 21 direct
## 22 direct
## 23 direct
## 24 direct
## 25 direct
## 26 direct
## 27 direct
## 28 direct
## 29 direct
## 30 direct
## 31 direct
## 32 direct
## 33 direct
## 34 direct
## 35 direct
## 36 direct
## 37 direct
## 38 direct
## 39 direct
## 40 direct
## 41 direct
## 42 direct
## 43 direct
## 44 direct
## 45 direct
## 46 direct
## 47 direct
## 48 direct
## 49 direct
## 50 direct
## 51 direct
## 52 direct
## 53 direct
## 54 direct
## 55 direct
## 56 direct
## 57 direct
## 58 direct
## 59 direct
## 60 direct
## 61 direct
## 62 direct
## 63 direct
## 64 direct
## 65 direct
## 66 direct
## 67 direct
## 68 direct
## 69 direct
## 70 direct
## 71 direct
## 72 direct
## 73 direct
## 74 direct
## 75 direct
## 76 direct
## 77 direct
## 78 direct
## 79 direct
## 80 direct
## 81 direct
## 82 direct
## 83 direct
## 84 direct
## 85 direct
## 86 direct
## 87 direct
## 88 direct
## 89 direct
## 90 direct
## 91 direct
## 92 direct
## 93 direct
## 94 direct
## 95 direct
## 96 direct
## 97 direct
## 98 direct
## 99 direct
## 100 direct
## 101 direct
max(BTC_Data$close)
## [1] 123374.6
#Question 3
# Title: Data-Driven Insights into the New York Giants–Dallas Cowboys Rivalry
# Research Questions:
# 1. Who has more wins historically, and how has the balance shifted by decade?
# 2. Do home/away games affect the rivalry outcome?
# 3. Are the games getting closer (smaller point differentials) in recent years?
# Find and extract datasets
# install.packages("rvest")
library(rvest)
NYG_vs_DC_alltime <- read_html("https://www.pro-football-reference.com/boxscores/game_query.cgi?tm1=dal&tm2=nyg&yr=all")
NYG_vs_DC_alltime_tbl <- html_elements(NYG_vs_DC_alltime, "table")
NYG_vs_DC_finaltbl <- html_table(NYG_vs_DC_alltime_tbl[[1]])
NYG_vs_DC_finaltbl
## # A tibble: 127 × 10
## Rk Date Day `` Tm `` Opp Tm Opp ``
## <int> <chr> <chr> <chr> <chr> <chr> <chr> <int> <int> <chr>
## 1 1 1960-12-04 Sun T Dallas Cowboys "@" New York… 31 31 boxs…
## 2 2 1961-10-15 Sun L Dallas Cowboys "" New York… 10 31 boxs…
## 3 3 1961-10-29 Sun W Dallas Cowboys "@" New York… 17 16 boxs…
## 4 4 1962-11-11 Sun L Dallas Cowboys "" New York… 10 41 boxs…
## 5 5 1962-12-16 Sun L Dallas Cowboys "@" New York… 31 41 boxs…
## 6 6 1963-10-20 Sun L Dallas Cowboys "@" New York… 21 37 boxs…
## 7 7 1963-12-01 Sun L Dallas Cowboys "" New York… 27 34 boxs…
## 8 8 1964-10-11 Sun T Dallas Cowboys "" New York… 13 13 boxs…
## 9 9 1964-11-08 Sun W Dallas Cowboys "@" New York… 31 21 boxs…
## 10 10 1965-09-19 Sun W Dallas Cowboys "" New York… 31 2 boxs…
## # ℹ 117 more rows
names(NYG_vs_DC_finaltbl) <- c("Rank", "Date", "Day of Game", "Outcome", "Team", "LoG", "Opponent", "Team Score", "Opponent Score", "Boxscore")
NYG_vs_DC_finaltbl$Rank <- NULL
NYG_vs_DC_finaltbl$Boxscore <- NULL
NYG_vs_DC_finaltbl$PointDifferential <- NYG_vs_DC_finaltbl$`Team Score` - NYG_vs_DC_finaltbl$`Opponent Score`
NYG_vs_DC_finaltbl$Outcome[NYG_vs_DC_finaltbl$Outcome == "W"] <- "Win"
NYG_vs_DC_finaltbl$Outcome[NYG_vs_DC_finaltbl$Outcome == "L"] <- "Loss"
NYG_vs_DC_finaltbl$Outcome[NYG_vs_DC_finaltbl$Outcome == "T"] <- "Tie"
NYG_vs_DC_finaltbl$LoG[NYG_vs_DC_finaltbl$LoG == ""] <- "Home"
NYG_vs_DC_finaltbl$LoG[NYG_vs_DC_finaltbl$LoG == "@"] <- "Away"
#Data Cleaning
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
NYG_vs_DC_finaltbl$Date <- ymd(as.character(NYG_vs_DC_finaltbl$Date))
str(NYG_vs_DC_finaltbl$Date)
## Date[1:127], format: "1960-12-04" "1961-10-15" "1961-10-29" "1962-11-11" "1962-12-16" ...
class(NYG_vs_DC_finaltbl$Date)
## [1] "Date"
NYG_vs_DC_finaltbl$`Day of Game` <- as.factor(NYG_vs_DC_finaltbl$`Day of Game`)
class(NYG_vs_DC_finaltbl$`Day of Game`)
## [1] "factor"
NYG_vs_DC_finaltbl$Outcome <- as.factor(NYG_vs_DC_finaltbl$Outcome)
class(NYG_vs_DC_finaltbl$Outcome)
## [1] "factor"
NYG_vs_DC_finaltbl$Team <- as.factor(NYG_vs_DC_finaltbl$Team)
class(NYG_vs_DC_finaltbl$Team)
## [1] "factor"
NYG_vs_DC_finaltbl$LoG <- as.factor(NYG_vs_DC_finaltbl$LoG)
NYG_vs_DC_finaltbl$Opponent <- as.factor(NYG_vs_DC_finaltbl$Opponent)
NYG_vs_DC_finaltbl$`Team Score` <- as.numeric(NYG_vs_DC_finaltbl$`Team Score`)
NYG_vs_DC_finaltbl$`Opponent Score` <- as.numeric(NYG_vs_DC_finaltbl$`Opponent Score`)
NYG_vs_DC_finaltbl$PointDifferential <- as.numeric(NYG_vs_DC_finaltbl$PointDifferential)
###New Cleaned Table
summary(NYG_vs_DC_finaltbl)
## Date Day of Game Outcome Team LoG
## Min. :1960-12-04 Mon: 13 Loss:47 Dallas Cowboys:127 Away:62
## 1st Qu.:1977-10-16 Sat: 3 Tie : 2 Home:65
## Median :1994-11-07 Sun:106 Win :78
## Mean :1993-12-30 Thu: 4
## 3rd Qu.:2009-10-28 Wed: 1
## Max. :2025-09-14
## Opponent Team Score Opponent Score PointDifferential
## New York Giants:127 Min. : 0.00 Min. : 0.00 Min. :-31.000
## 1st Qu.:16.00 1st Qu.:13.00 1st Qu.: -4.000
## Median :23.00 Median :20.00 Median : 3.000
## Mean :23.55 Mean :19.24 Mean : 4.307
## 3rd Qu.:31.00 3rd Qu.:28.00 3rd Qu.: 13.500
## Max. :52.00 Max. :41.00 Max. : 45.000
NYG_vs_DC_finaltbl
## # A tibble: 127 × 9
## Date `Day of Game` Outcome Team LoG Opponent `Team Score`
## <date> <fct> <fct> <fct> <fct> <fct> <dbl>
## 1 1960-12-04 Sun Tie Dallas Cowboys Away New York … 31
## 2 1961-10-15 Sun Loss Dallas Cowboys Home New York … 10
## 3 1961-10-29 Sun Win Dallas Cowboys Away New York … 17
## 4 1962-11-11 Sun Loss Dallas Cowboys Home New York … 10
## 5 1962-12-16 Sun Loss Dallas Cowboys Away New York … 31
## 6 1963-10-20 Sun Loss Dallas Cowboys Away New York … 21
## 7 1963-12-01 Sun Loss Dallas Cowboys Home New York … 27
## 8 1964-10-11 Sun Tie Dallas Cowboys Home New York … 13
## 9 1964-11-08 Sun Win Dallas Cowboys Away New York … 31
## 10 1965-09-19 Sun Win Dallas Cowboys Home New York … 31
## # ℹ 117 more rows
## # ℹ 2 more variables: `Opponent Score` <dbl>, PointDifferential <dbl>