install.packages(“jsonlite”, repos = “https://cloud.r-project.org”) library(jsonlite) — title: “BTC Historical Data Analysis” output: html_document —

# Install and load jsonlite
if (!require(jsonlite)) {
  install.packages("jsonlite", repos = "https://cloud.r-project.org")
}
## Loading required package: jsonlite
library(jsonlite)

# Pull BTC historical data (last 100 days) from CryptoCompare API

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

# Read JSON data from the URL

btc_data_raw <- fromJSON(url)

# Extract the nested data frame

btc_df <- btc_data_raw$Data$Data

# Convert Unix time to readable dates

btc_df$time <- as.POSIXct(btc_df$time, origin = "1970-01-01")

# Find the maximum closing price

max_close <- max(btc_df$close)

# Display the result

cat("The maximum daily closing price of BTC in the last 100 days (USD) is:", max_close, "\n")
## The maximum daily closing price of BTC in the last 100 days (USD) is: 124723
# Plot the daily closing prices

plot(
btc_df$close,
type = "l",
main = "BTC Daily Close (Last 100 Days)",
ylab = "Closing Price (USD)",
xlab = "Day"
)