Question 1
data(cars)
median(cars[, 1])
## [1] 15
Question 2
# avoid CRAN mirror error when installing
options(repos = c(CRAN = "https://cloud.r-project.org"))
# install/load jsonlite (for JSON)
if (!requireNamespace("jsonlite", quietly = TRUE)) {
install.packages("jsonlite")
}
library(jsonlite)
# build the URL (BTC in USD, last 100 days)
url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=99"
# fetch JSON
raw <- fromJSON(url)
# quick sanity checks
if (!identical(raw$Response, "Success")) {
stop("API call did not return Success. Maybe try again later.")
}
# the data we want is inside $Data$Data (list -> data frame)
dat <- raw$Data$Data
# make a readable datetime column from UNIX epoch 'time'
dat$datetime_utc <- as.POSIXct(dat$time, origin = "1970-01-01", tz = "UTC")
# compute the max daily close
max_close <- max(dat$close, na.rm = TRUE)
# also grab the date it happened on (in UTC)
row_max <- dat[which.max(dat$close), c("datetime_utc", "close")]
# show results
cat("Max BTC daily close (last 100 days):", sprintf("%.2f USD", max_close), "\n")
## Max BTC daily close (last 100 days): 124723.00 USD
cat("Happened on (UTC):", format(row_max$datetime_utc, "%Y-%m-%d"), "\n")
## Happened on (UTC): 2025-10-06