1. Warm-up: Cars Dataset Median

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

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

Answer: The median of the first column is 15.


2. Extracting Bitcoin Data via API

I’ll use the CryptoCompare API to retrieve daily BTC-USD prices for the past 100 days.
This demonstrates working with JSON data.

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

# Read JSON
btc_data <- fromJSON(url)

# Inspect structure
str(btc_data, 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:
# Extract DataFrame
df <- btc_data$Data$Data

# Convert time to date
df$time <- as.POSIXct(df$time, origin="1970-01-01")

# Preview data
head(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
## 1         direct                 
## 2         direct                 
## 3         direct                 
## 4         direct                 
## 5         direct                 
## 6         direct

Now I’ll find the maximum daily close price:

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

Answer: This returns the max daily close over the 100 days (value depends on current data).


4. Quiz Questions & Answers

Below are the answers to the quiz associated with this assignment:

Q1: Median of first column in cars dataset?
C. 15

Q2: Extract BTC data and find max close.
✅ Code shown in Section 2, answer depends on latest data.

Q3: Mini project steps (Title, Questions, Data, Cleaning, Imputation).
✅ Completed in Section 3.

Q4: Presentation Bonus.
✅ If presented, click True.