Question 1

Load the dataset and determine the median?
pacman::p_load(JSONlite, httr)
## Installing package into 'C:/Users/lcunn/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## Warning: package 'JSONlite' is not available for this version of R
## 
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: Perhaps you meant 'jsonlite' ?
## Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/4.4:
##   cannot open URL 'http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/4.4/PACKAGES'
## Warning: 'BiocManager' not available.  Could not check Bioconductor.
## 
## Please use `install.packages('BiocManager')` and then retry.
## Warning in p_install(package, character.only = TRUE, ...):
## Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
## logical.return = TRUE, : there is no package called 'JSONlite'
## Warning in pacman::p_load(JSONlite, httr): Failed to install/load:
## JSONlite
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(jsonlite)
data(cars)
median(cars$speed)
## [1] 15

Question 2

How many observations and variables in the dataset?
on_time_performance <- read.csv("on_time_performance.csv")

dim(on_time_performance)
## [1] 570131    110
nrow(on_time_performance)
## [1] 570131
ncol(on_time_performance)
## [1] 110

Question 3

How many columns are missing in Div2WheelsOff?
sum(is.na(on_time_performance$Div2WheelsOff))
## [1] 570122

Question 4

Find average departure delay by carrier
avg_delay_by_carrier <- on_time_performance %>%
  group_by(Carrier) %>%  # Ensure 'Carrier' is the correct column name
  summarise(avg_dep_delay = mean(DepDelayMinutes, na.rm = TRUE)) %>%  # Use 'DepDelayMinutes'
  arrange(desc(avg_dep_delay))  # Sort in descending order

print(avg_delay_by_carrier)
## # A tibble: 18 × 2
##    Carrier avg_dep_delay
##    <chr>           <dbl>
##  1 B6              24.1 
##  2 F9              19.7 
##  3 OO              19.6 
##  4 EV              18.2 
##  5 9E              16.7 
##  6 OH              16.6 
##  7 G4              14.6 
##  8 YV              12.8 
##  9 DL              12.5 
## 10 MQ              12.1 
## 11 YX              11.5 
## 12 NK              10.4 
## 13 AA              10.3 
## 14 WN               9.92
## 15 UA               9.80
## 16 VX               8.18
## 17 HA               5.44
## 18 AS               4.90
largest_delay_carrier <- avg_delay_by_carrier %>%
  slice(1)  # Select the top carrier

print(largest_delay_carrier)
## # A tibble: 1 × 2
##   Carrier avg_dep_delay
##   <chr>           <dbl>
## 1 B6               24.1
# Define the API endpoint
url <- "https://min-api.cryptocompare.com/data/v2/histoday"

# Define parameters
params <- list(
  fsym = "BTC",      # Cryptocurrency symbol (Bitcoin)
  tsym = "USD",      # Measured in USD
  limit = 100        # Last 100 days
)

# Send GET request with parameters
response <- GET(url, query = params)

# Parse JSON response
BT_Data <- fromJSON(content(response, as = "text"))

# Extract closing prices
BTC <- BT_Data$Data$Data$close

# Check if BTC contains valid data
if (length(BTC) > 0 && all(!is.na(BTC))) {
  print(max(BTC))  # Get max closing price
} else {
  print("No valid data retrieved.")
}
## [1] 106155.6