data(cars)
summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
library("jsonlite")

##How has the average daily temperature changed over time?

##Which months experienced the highest and lowest average temperatures in 2024?

##Which months have the highest amount of precipitation

histoday <- fromJSON("https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=99")
sublist <- histoday$Data$Data
max <- max(sublist$close, na.rm = TRUE)

max
## [1] 124723

#3

library(rvest)
library(readr)
## 
## Attaching package: 'readr'
## The following object is masked from 'package:rvest':
## 
##     guess_encoding
data <- read.csv("https://www.ncei.noaa.gov/data/global-summary-of-the-day/access/2024/01001099999.csv")
readLines("~/Desktop/Weather.csv", n = 10)
##  [1] "01001099999"                                                                                                                                                                                                                                                 
##  [2] "STATION,DATE,LATITUDE,LONGITUDE,ELEVATION,NAME,TEMP,TEMP_ATTRIBUTES,DEWP,DEWP_ATTRIBUTES,SLP,SLP_ATTRIBUTES,STP,STP_ATTRIBUTES,VISIB,VISIB_ATTRIBUTES,WDSP,WDSP_ATTRIBUTES,MXSPD,GUST,MAX,MAX_ATTRIBUTES,MIN,MIN_ATTRIBUTES,PRCP,PRCP_ATTRIBUTES,SNDP,FRSHTT"
##  [3] "1001099999,2025-01-01,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",17.4,8,10.3,8,1014.9,8,13.7,8,2.0,4,20.9,8,27.2,39.4,24.4, ,9.7, ,0.05,G,999.9,1000"                                                                                              
##  [4] "1001099999,2025-01-02,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",12.0,9,6.5,9,1014.6,9,13.4,9,1.5,4,23.8,9,29.1,48.6,16.9, ,8.2, ,0.02,G,999.9,0"                                                                                                  
##  [5] "1001099999,2025-01-03,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",20.7,8,15.4,8,1011.9,8,10.7,8,2.7,4,24.5,8,30.9,43.9,23.9, ,15.1, ,0.02,G,999.9,1000"                                                                                             
##  [6] "1001099999,2025-01-04,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",22.1,8,15.8,8,1010.5,8,9.3,8,6.2,4,19.6,8,24.5,35.4,23.9, ,19.8, ,0.00,G,999.9,1000"                                                                                              
##  [7] "1001099999,2025-01-05,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",26.5,8,22.6,8,1009.9,8,8.7,8,3.7,4,23.8,8,28.9,39.4,30.9, ,19.6, ,0.00,G,999.9,11000"                                                                                             
##  [8] "1001099999,2025-01-06,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",29.1,8,21.9,8,1016.6,8,15.4,8,14.0,4,15.2,8,24.9,33.8,31.8, ,26.4, ,0.01,G,999.9,0"                                                                                               
##  [9] "1001099999,2025-01-07,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",26.3,7,19.5,7,1015.5,7,14.3,7,9.3,4,14.4,7,23.1,33.4,27.7, ,23.9, ,0.00,G,999.9,1000"                                                                                             
## [10] "1001099999,2025-01-08,70.9333333,-8.6666667,9.0,\"JAN MAYEN NOR NAVY, NO\",24.5,8,16.7,8,1014.9,8,13.7,8,14.0,4,11.2,8,17.5,34.0,29.7, ,20.7, ,0.01,G,999.9,0"
weather <- read.csv("~/Downloads/Weather_fixed.csv")
names(weather)
##  [1] "STATION"          "DATE"             "LATITUDE"         "LONGITUDE"       
##  [5] "ELEVATION"        "NAME"             "TEMP"             "TEMP_ATTRIBUTES" 
##  [9] "DEWP"             "DEWP_ATTRIBUTES"  "SLP"              "SLP_ATTRIBUTES"  
## [13] "STP"              "STP_ATTRIBUTES"   "VISIB"            "VISIB_ATTRIBUTES"
## [17] "WDSP"             "WDSP_ATTRIBUTES"  "MXSPD"            "GUST"            
## [21] "MAX"              "MAX_ATTRIBUTES"   "MIN"              "MIN_ATTRIBUTES"  
## [25] "PRCP"             "PRCP_ATTRIBUTES"  "SNDP"             "FRSHTT"
weather_new <- weather[, c("DATE", "TEMP", "PRCP")]
weather_clean <- weather_new
weather_clean$DATE <- as.Date(weather_clean$DATE)
summary(weather_clean)
##       DATE                 TEMP            PRCP       
##  Min.   :2025-01-01   Min.   :11.80   Min.   : 0.000  
##  1st Qu.:2025-02-28   1st Qu.:27.88   1st Qu.: 0.000  
##  Median :2025-04-28   Median :33.85   Median : 0.010  
##  Mean   :2025-04-28   Mean   :34.24   Mean   : 1.737  
##  3rd Qu.:2025-06-26   3rd Qu.:41.52   3rd Qu.: 0.050  
##  Max.   :2025-08-24   Max.   :52.50   Max.   :99.990
weather_clean <- na.omit(weather_clean)
head(weather_clean)
##         DATE TEMP PRCP
## 1 2025-01-01 17.4 0.05
## 2 2025-01-02 12.0 0.02
## 3 2025-01-03 20.7 0.02
## 4 2025-01-04 22.1 0.00
## 5 2025-01-05 26.5 0.00
## 6 2025-01-06 29.1 0.01
plot(weather_clean$DATE, weather_clean$TEMP, type="l",
     col="red", lwd=2,
     main="Daily Temperature Trend",
     xlab="Date", ylab="Temperature (°F)")

weather_clean$month <- format(weather_clean$DATE, "%m")
monthly_avg <- aggregate(cbind(TEMP, PRCP) ~ month, data = weather_clean, FUN = mean)
monthly_avg
##   month     TEMP       PRCP
## 1    01 25.20323 6.48741935
## 2    02 30.04643 3.65035714
## 3    03 24.95806 3.26000000
## 4    04 28.94333 0.02900000
## 5    05 35.30968 0.01064516
## 6    06 39.30667 0.05033333
## 7    07 46.20323 0.02580645
## 8    08 46.27083 0.08416667