1. Warm-up: Cars Dataset Median (10 pts)

The built-in cars dataset contains the speed and stopping distances of cars.
Here I compute the median of the first column (speed):

# Load cars dataset
data(cars)

# Compute median speed
median_speed <- median(cars[, 1])
median_speed
## [1] 15

Answer: The median of the first column is 15.


2. Extracting Bitcoin Data via API (20 pts)

I will retrieve daily BTC–USD price data for the past 100 days from CryptoCompare.
The data is in JSON format, so I will use jsonlite::fromJSON().

# Load required package
library(jsonlite)

# Construct the URL for 100 days of BTC-USD daily data
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100"

# Retrieve JSON data
btc_raw <- fromJSON(url)

# Inspect structure
str(btc_raw, max.level = 2)
## List of 6
##  $ Response  : chr "Success"
##  $ Message   : chr ""
##  $ HasWarning: logi FALSE
##  $ Type      : int 100
##  $ RateLimit : Named list()
##  $ Data      :List of 4
##   ..$ Aggregated: logi FALSE
##   ..$ TimeFrom  : int 1751155200
##   ..$ TimeTo    : int 1759795200
##   ..$ Data      :'data.frame':   101 obs. of  9 variables:

The price data is stored under btc_raw$Data$Data.
I’ll extract it into a clean data frame and compute the maximum daily close price.

# Extract the data sublist
btc_df <- btc_raw$Data$Data

# Convert timestamp to Date format
btc_df$time <- as.POSIXct(btc_df$time, origin = "1970-01-01")
btc_df$date <- as.Date(btc_df$time)

# Look at first few rows
head(btc_df)
##                  time     high      low     open volumefrom   volumeto    close
## 1 2025-06-28 20:00:00 108538.4 107233.6 107346.4    6094.35  657403121 108391.9
## 2 2025-06-29 20:00:00 108815.7 106756.4 108391.9   14220.51 1530756559 107169.8
## 3 2025-06-30 20:00:00 107574.1 105295.0 107169.8   15730.48 1673173145 105724.2
## 4 2025-07-01 20:00:00 109818.5 105143.1 105724.2   19611.45 2124516059 108886.6
## 5 2025-07-02 20:00:00 110584.4 108579.6 108886.6   16647.63 1825182142 109639.0
## 6 2025-07-03 20:00:00 109810.0 107283.9 109639.0   10440.09 1130647601 108027.7
##   conversionType conversionSymbol       date
## 1         direct                  2025-06-29
## 2         direct                  2025-06-30
## 3         direct                  2025-07-01
## 4         direct                  2025-07-02
## 5         direct                  2025-07-03
## 6         direct                  2025-07-04

Now compute the maximum closing price:

max_close <- max(btc_df$close, na.rm = TRUE)
max_close
## [1] 124723

Answer: The maximum daily close price for BTC over the past 100 days is 1.24723^{5} USD.