Excercise 1

myfun <- function(vec, m = 40) {
  x <- sample(vec, m)
  s <- NULL
  d <- NULL
  for (i in x) {
    if (i <= 150 && i %% 4 == 0) {
      s <- c(s, i)
    } else if (i > 150 && i %% 3 == 0) {
      d <- c(d, i)
    }
  }
  mean_s <- mean(s)
  var_s <- var(s)
  mean_d <- mean(d)
  var_d <- var(d)
  l <- list(selected_integers = x, s = s, d = d, mean_s = mean_s, var_s = var_s, mean_d = mean_d, var_d = var_d)
  return(l)
}

# Applying the function to a sample containing 40 randomly selected integers from vec = c(1:300)
set.seed(123)  # For reproducibility
result <- myfun(1:300)
print(result)
## $selected_integers
##  [1] 179  14 195 118 229 244 299 153  90  91 256 197 291 137  26   7 287 254 211
## [20]  78  81  43 143  32 109 263  23 135 224 166 217  69  72  76  63 141 210 293
## [39]  41 292
## 
## $s
## [1] 32 72 76
## 
## $d
## [1] 195 153 291 210
## 
## $mean_s
## [1] 60
## 
## $var_s
## [1] 592
## 
## $mean_d
## [1] 212.25
## 
## $var_d
## [1] 3338.25

Exercise 2

x <- seq(-5, 40, length=500)         # x values
dist_x <- dnorm(x, mean = 10, sd = 10)    # Returns CDF of normal distribution with mean 10 and sd 10.

degf <- c(5, 8, 18)             # Set up the three degrees of freedom
colors <- c("green", "red", "blue", "black")  # Set up the four colors 
labels <- c("df=5", "df=8", "df=18", "normal")       # Label the plots

plot(x, dist_x, type="l", lty=2, lwd=2, xlab="x value",
  ylab="Density", main="Comparison of Normal and Chi-square Distributions")         # Plot normal density curve

for (i in seq_along(degf)){
  lines(x, dchisq(x, degf[i]), lty=1, lwd=2, col=colors[i]) # Plot chi-square distribution curves
}

legend("topright", inset=0.01, title="Distributions",       # Set up the title of legend
  labels, lwd=2, lty=c(2, 1, 1, 1), col=colors)  # Set up line types appearing in the legend

Exercise 3

## Warning: package 'ggridges' was built under R version 4.3.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Picking joint bandwidth of 0.203
## Warning: The following aesthetics were dropped during statistical transformation: fill
## ℹ This can happen when ggplot fails to infer the correct grouping structure in
##   the data.
## ℹ Did you forget to specify a `group` aesthetic or to convert a numerical
##   variable into a factor?
(ref:label4)

(ref:label4)

Exercise 4

# Load required libraries
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## Warning: package 'tidyr' was built under R version 4.3.2
## Warning: package 'purrr' was built under R version 4.3.2
## Warning: package 'forcats' was built under R version 4.3.2
## Warning: package 'lubridate' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Temp Plots
#2020
# Extract month from Date
Temp_2020$Month <- month(Temp_2020$'Date Local', label = TRUE)

# Create a boxplot for Temp
p <- ggplot(Temp_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Temp in 2020",
       x = "Month",
       y = "Temp in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021
# Extract month from Date
Temp_2021$Month <- month(Temp_2021$'Date Local', label = TRUE)

# Create a boxplot for Temp
p <- ggplot(Temp_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Temp in 2021",
       x = "Month",
       y = "Temp in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022
# Extract month from Date
Temp_2022$Month <- month(Temp_2022$'Date Local', label = TRUE)

# Create a boxplot for Temp
p <- ggplot(Temp_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Temp in 2022",
       x = "Month",
       y = "Temp in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# RH_DP Plot
#2020

# Extract month from Date
RH_DP_2020$Month <- month(RH_DP_2020$'Date Local', label = TRUE)

# Create a boxplot for Relative Humidity
p <- ggplot(RH_DP_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Relative Humidity in 2020",
       x = "Month",
       y = "Relative Humidity in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021

# Extract month from Date
RH_DP_2021$Month <- month(RH_DP_2021$'Date Local', label = TRUE)

# Create a boxplot for Relative Humidity
p <- ggplot(RH_DP_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Relative Humidity in 2021",
       x = "Month",
       y = "Relative Humidity in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022

# Extract month from Date
RH_DP_2022$Month <- month(RH_DP_2022$'Date Local', label = TRUE)

# Create a boxplot for Relative Humidity
p <- ggplot(RH_DP_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Relative Humidity in 2022",
       x = "Month",
       y = "Relative Humidity in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# Wind Plot
#2020
# Extract month from Date
Wind_2020$Month <- month(Wind_2020$'Date Local', label = TRUE)

# Create a boxplot for Wind
p <- ggplot(Wind_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Wind in 2020",
       x = "Month",
       y = "Wind in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021
# Extract month from Date
Wind_2021$Month <- month(Wind_2021$'Date Local', label = TRUE)

# Create a boxplot for Wind
p <- ggplot(Wind_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Wind in 2021",
       x = "Month",
       y = "Wind in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022
# Extract month from Date
Wind_2022$Month <- month(Wind_2022$'Date Local', label = TRUE)

# Create a boxplot for Wind
p <- ggplot(Wind_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Wind in 2022r",
       x = "Month",
       y = "Wind in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# NO2 Plot
#2020
# Extract month from Date
NO2_2020$Month <- month(NO2_2020$'Date Local', label = TRUE)

# Create a boxplot for NO2
p <- ggplot(NO2_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of NO2 in 2020",
       x = "Month",
       y = "NO2 in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021
# Extract month from Date
NO2_2021$Month <- month(NO2_2021$'Date Local', label = TRUE)

# Create a boxplot for NO2
p <- ggplot(NO2_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of NO2 in 2021",
       x = "Month",
       y = "NO2 in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022
# Extract month from Date
NO2_2022$Month <- month(NO2_2022$'Date Local', label = TRUE)

# Create a boxplot for NO2
p <- ggplot(NO2_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of NO2 in 2022",
       x = "Month",
       y = "NO2 in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# SO2 Plot
# 2020
# Extract month from Date
SO2_2020$Month <- month(SO2_2020$'Date Local', label = TRUE)

# Create a boxplot for SO2
p <- ggplot(SO2_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of SO2 in 2020",
       x = "Month",
       y = "SO2 in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# 2021
# Extract month from Date
SO2_2021$Month <- month(SO2_2021$'Date Local', label = TRUE)

# Create a boxplot for SO2
p <- ggplot(SO2_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of SO2 in 2021",
       x = "Month",
       y = "SO2 in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# 2022
# Extract month from Date
SO2_2022$Month <- month(SO2_2022$'Date Local', label = TRUE)

# Create a boxplot for SO2
p <- ggplot(SO2_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of SO2 in 2022",
       x = "Month",
       y = "SO2 in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# OZ Plot
#2020
# Extract month from Date
OZ_2020$Month <- month(OZ_2020$'Date Local', label = TRUE)

# Create a boxplot for OZ
p <- ggplot(OZ_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of OZ in 2020",
       x = "Month",
       y = "OZ in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021
# Extract month from Date
OZ_2021$Month <- month(OZ_2021$'Date Local', label = TRUE)

# Create a boxplot for OZ
p <- ggplot(OZ_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of OZ in 2021",
       x = "Month",
       y = "OZ in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022
# Extract month from Date
OZ_2022$Month <- month(OZ_2022$'Date Local', label = TRUE)

# Create a boxplot for OZ
p <- ggplot(OZ_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of OZ in 2022",
       x = "Month",
       y = "OZ in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

# CO Plot
#2020
# Extract month from Date
CO_2020$Month <- month(CO_2020$'Date Local', label = TRUE)

# Create a boxplot for CO
p <- ggplot(CO_2020, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of CO in 2020",
       x = "Month",
       y = "CO in 2020",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2021
# Extract month from Date
CO_2021$Month <- month(CO_2021$'Date Local', label = TRUE)

# Create a boxplot for CO
p <- ggplot(CO_2021, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of CO in 2021",
       x = "Month",
       y = "CO in 2021",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

#2022
# Extract month from Date
CO_2022$Month <- month(CO_2022$'Date Local', label = TRUE)

# Create a boxplot for CO
p <- ggplot(CO_2022, aes(x = Month, y = `Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of CO in 2022",
       x = "Month",
       y = "CO in 2022",
       fill = "Month") +
  theme(legend.position = "bottom", legend.box = "horizontal")

# Display the plot
print(p)

Exercise 5

# Load required libraries
library(tidyverse)
library(plotly)
## Warning: package 'plotly' was built under R version 4.3.2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
MV_2020 <- rbind(Temp_sd_2020, RH_DP_sd_2020, Wind_sd_2020)
MV_2021 <- rbind(Temp_sd_2021, RH_DP_sd_2021, Wind_sd_2021)
MV_2022 <- rbind(Temp_sd_2022, RH_DP_sd_2022, Wind_sd_2022)

# create plotly for 2020

# Extract month from Date
MV_2020$Month <- month(MV_2020$'Date Local', label = TRUE)


# Create a ggplot object
p <- ggplot(MV_2020, aes(x = Month, y = MV_2020$`Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Meteorological Variables Across Months (2020)",
       x = "Month",
       y = "Value",
       fill = "Month") +
  facet_wrap(~`Parameter Name`, scales = "free_y") +
  theme(legend.position = "bottom", legend.box = "horizontal", legend.title = element_blank())

# Convert ggplot to plotly
p <- ggplotly(p)
## Warning: Use of `` MV_2020$`Arithmetic Mean` `` is discouraged.
## ℹ Use `Arithmetic Mean` instead.
# Display the plot
p
# Create plotly for 2021

# Extract month from Date
MV_2021$Month <- month(MV_2021$'Date Local', label = TRUE)


# Create a ggplot object
p <- ggplot(MV_2021, aes(x = Month, y = MV_2021$`Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Meteorological Variables Across Months (2021)",
       x = "Month",
       y = "Value",
       fill = "Month") +
  facet_wrap(~`Parameter Name`, scales = "free_y") +
  theme(legend.position = "bottom", legend.box = "horizontal", legend.title = element_blank())

# Convert ggplot to plotly
p <- ggplotly(p)
## Warning: Use of `` MV_2021$`Arithmetic Mean` `` is discouraged.
## ℹ Use `Arithmetic Mean` instead.
# Display the plot
p
# create plotly for 2022

# Extract month from Date
MV_2022$Month <- month(MV_2022$'Date Local', label = TRUE)


# Create a ggplot object
p <- ggplot(MV_2022, aes(x = Month, y = MV_2022$`Arithmetic Mean`, fill = Month)) +
  geom_boxplot() +
  labs(title = "Boxplot of Meteorological Variables Across Months (2022)",
       x = "Month",
       y = "Value",
       fill = "Month") +
  facet_wrap(~`Parameter Name`, scales = "free_y") +
  theme(legend.position = "bottom", legend.box = "horizontal", legend.title = element_blank())

# Convert ggplot to plotly
p <- ggplotly(p)
## Warning: Use of `` MV_2022$`Arithmetic Mean` `` is discouraged.
## ℹ Use `Arithmetic Mean` instead.
# Display the plot
p

Exercise 6

# Count frost days
frost_days <- sum(Temp_SD$`Arithmetic Mean` < 32)

# Count hot days
hot_days <- sum(Temp_SD$`Arithmetic Mean` > 80)

# Display the results
cat("Number of Frost Days:", frost_days, "\n")
## Number of Frost Days: 389
cat("Number of Hot Days:", hot_days, "\n")
## Number of Hot Days: 53

Exercise 7

# Create a subset for the Summer season (June, July, August)
Summer <- rbind(summer_CO, summer_NO2, summer_OZ, summer_SO2, summer_Temp,
                summer_Wind, summer_RH_DP)


# Create a subset for the Winter season (January, February, December)
Winter <- rbind(winter_CO, winter_NO2, winter_OZ, winter_SO2, winter_Temp,
                winter_Winds, winter_RH_DP)



head(Summer)
## # A tibble: 6 × 29
##   `State Code` `County Code` `Site Num` `Parameter Code`   POC Latitude
##   <chr>        <chr>         <chr>                 <dbl> <dbl>    <dbl>
## 1 46           099           0008                  42101     3     43.5
## 2 46           099           0008                  42101     3     43.5
## 3 46           099           0008                  42101     3     43.5
## 4 46           099           0008                  42101     3     43.5
## 5 46           099           0008                  42101     3     43.5
## 6 46           099           0008                  42101     3     43.5
## # ℹ 23 more variables: Longitude <dbl>, Datum <chr>, `Parameter Name` <chr>,
## #   `Sample Duration` <chr>, `Pollutant Standard` <chr>, `Date Local` <date>,
## #   `Units of Measure` <chr>, `Event Type` <chr>, `Observation Count` <dbl>,
## #   `Observation Percent` <dbl>, `Arithmetic Mean` <dbl>,
## #   `1st Max Value` <dbl>, `1st Max Hour` <dbl>, AQI <dbl>,
## #   `Method Code` <chr>, `Method Name` <chr>, `Local Site Name` <chr>,
## #   Address <chr>, `State Name` <chr>, `County Name` <chr>, …
head(Winter)
## # A tibble: 6 × 29
##   `State Code` `County Code` `Site Num` `Parameter Code`   POC Latitude
##   <chr>        <chr>         <chr>                 <dbl> <dbl>    <dbl>
## 1 46           099           0008                  42101     3     43.5
## 2 46           099           0008                  42101     3     43.5
## 3 46           099           0008                  42101     3     43.5
## 4 46           099           0008                  42101     3     43.5
## 5 46           099           0008                  42101     3     43.5
## 6 46           099           0008                  42101     3     43.5
## # ℹ 23 more variables: Longitude <dbl>, Datum <chr>, `Parameter Name` <chr>,
## #   `Sample Duration` <chr>, `Pollutant Standard` <chr>, `Date Local` <date>,
## #   `Units of Measure` <chr>, `Event Type` <chr>, `Observation Count` <dbl>,
## #   `Observation Percent` <dbl>, `Arithmetic Mean` <dbl>,
## #   `1st Max Value` <dbl>, `1st Max Hour` <dbl>, AQI <dbl>,
## #   `Method Code` <chr>, `Method Name` <chr>, `Local Site Name` <chr>,
## #   Address <chr>, `State Name` <chr>, `County Name` <chr>, …
dim(Summer)
## [1] 6174   29
dim(Winter)
## [1] 6973   29

Exercise 8

# Calculate mean daily for each variable during Summer and Winter
meantemp_summer_2020 <- mean(summer_Temp_2020$`Arithmetic Mean`)
meantemp_summer_2021 <- mean(summer_Temp_2021$`Arithmetic Mean`)
meantemp_summer_2022 <- mean(summer_Temp_2022$`Arithmetic Mean`)
meanwinds_summer_2020 <- mean(summer_Winds_2020$`Arithmetic Mean`)
meanwinds_summer_2021 <- mean(summer_Winds_2021$`Arithmetic Mean`)
meanwinds_summer_2022 <- mean(summer_Winds_2022$`Arithmetic Mean`)
meanRH_DP_summer_2020 <- mean(summer_RHDP_2020$`Arithmetic Mean`)
meanRH_DP_summer_2021 <- mean(summer_RHDP_2021$`Arithmetic Mean`)
meanRH_DP_summer_2022 <- mean(summer_RHDP_2022$`Arithmetic Mean`)
meantemp_winter_2020 <- mean(winter_Temp_2020$`Arithmetic Mean`)
meantemp_winter_2021 <- mean(winter_Temp_2021$`Arithmetic Mean`)
meantemp_winter_2022 <- mean(winter_Temp_2022$`Arithmetic Mean`)
meanwinds_winter_2020 <- mean(winter_Winds_2020$`Arithmetic Mean`)
meanwinds_winter_2021 <- mean(winter_winds_2021$`Arithmetic Mean`)
meanwinds_winter_2022 <- mean(winter_Winds_2022$`Arithmetic Mean`)
meanRH_DP_winter_2020 <- mean(winter_RHDP_2020$`Arithmetic Mean`)
meanRH_DP_winter_2021 <- mean(winter_RHDP_2021$`Arithmetic Mean`)
meanRH_DP_winter_2022 <- mean(winter_RHDP_2022$`Arithmetic Mean`)

# Print the calculated means
cat("Mean Temp in Summer in 2020:", meantemp_summer_2020, "degrees farenheit\n")
## Mean Temp in Summer in 2020: 72.42837 degrees farenheit
cat("Mean Temp in Summer in 2021:", meantemp_summer_2021, "degrees farenheit\n")
## Mean Temp in Summer in 2021: 74.55649 degrees farenheit
cat("Mean Temp in Summer in 2022:", meantemp_summer_2022, "degrees farenheit\n")
## Mean Temp in Summer in 2022: 72.10724 degrees farenheit
cat("Mean Temp in Winter in 2020:", meantemp_winter_2020, "degrees farenheit\n")
## Mean Temp in Winter in 2020: 37.94846 degrees farenheit
cat("Mean Temp in Winter in 2021:", meantemp_winter_2021, "degrees farenheit\n")
## Mean Temp in Winter in 2021: 26.24282 degrees farenheit
cat("Mean Temp in Winter in 2022:", meantemp_winter_2022, "degrees farenheit\n")
## Mean Temp in Winter in 2022: 25.37438 degrees farenheit
cat("Mean Winds in Summer in 2020", meanwinds_summer_2020, "knots/degrees\n")
## Mean Winds in Summer in 2020 98.48663 knots/degrees
cat("Mean Winds in Summer in 2021", meanwinds_summer_2021, "knots/degrees\n")
## Mean Winds in Summer in 2021 90.41046 knots/degrees
cat("Mean Winds in Summer in 2022", meanwinds_summer_2022, "knots/degrees\n")
## Mean Winds in Summer in 2022 101.6477 knots/degrees
cat("Mean Winds in Winter in 2020", meanwinds_winter_2020, "knots/degrees\n")
## Mean Winds in Winter in 2020 72.79923 knots/degrees
cat("Mean Winds in Winter in 2021", meanwinds_winter_2021, "knots/degrees\n")
## Mean Winds in Winter in 2021 100.4268 knots/degrees
cat("Mean Winds in Winter in 2022", meanwinds_winter_2022, "knotsdegrees\n")
## Mean Winds in Winter in 2022 145.5958 knotsdegrees
cat("Mean Relative Humidity in Summer in 2020:", meanRH_DP_summer_2020, "%\n")
## Mean Relative Humidity in Summer in 2020: 50.04484 %
cat("Mean Relative Humidity in Summer in 2021:", meanRH_DP_summer_2021, "%\n")
## Mean Relative Humidity in Summer in 2021: 59.71301 %
cat("Mean Relative Humidity in Summer in 2022:", meanRH_DP_summer_2022, "%\n")
## Mean Relative Humidity in Summer in 2022: 46.06148 %
cat("Mean Relative Humidity in Winter in 2020:", meanRH_DP_winter_2020, "%\n")
## Mean Relative Humidity in Winter in 2020: 67.39349 %
cat("Mean Relative Humidity in Winter in 2021:", meanRH_DP_winter_2021, "%\n")
## Mean Relative Humidity in Winter in 2021: 66.17228 %
cat("Mean Relative Humidity in Winter in 2022:", meanRH_DP_winter_2022, "%\n")
## Mean Relative Humidity in Winter in 2022: 73.36935 %

Exercise 9

summer_Temp$Temperature_Difference <- summer_Temp$`1st Max Value` - summer_Temp$`Arithmetic Mean`

# Sort the differences by increasing order within each year
sorted_data <- summer_Temp[order(-summer_Temp$Temperature_Difference), ]

# Got values from looking at the new sorted data column

# Print top ten
cat("Top Ten Temperature Differences: 24.96\n")
## Top Ten Temperature Differences: 24.96
cat("                                 19.29\n")
##                                  19.29
cat("                                 19.00\n")
##                                  19.00
cat("                                 18.29\n")
##                                  18.29
cat("                                 17.88\n")
##                                  17.88
cat("                                 17.88\n")
##                                  17.88
cat("                                 17.54\n")
##                                  17.54
cat("                                 17.50\n")
##                                  17.50
cat("                                 16.63\n")
##                                  16.63
cat("                                 16.38")
##                                  16.38

Exercise 10 (Too many apps)

# Load required libraries
library(shiny)
library(tidyverse)
# Remove character variables
weather_numeric <- select_if(weather, is.numeric)

# Define UI for application
ui <- fluidPage(
  titlePanel("Interactive Histograms for Weather Data"),
  sidebarLayout(
    sidebarPanel(
      selectInput("column", "Select Column", choices = colnames(weather_numeric)),
      sliderInput("bins", "Number of Bins", min = 1, max = 50, value = 10)
    ),
    mainPanel(
      plotOutput("histogram")
    )
  )
)

# Define server logic
server <- function(input, output) {
  output$histogram <- renderPlot({
    ggplot(weather_numeric, aes(x = !!sym(input$column))) +
      geom_histogram(bins = input$bins, fill = "blue", color = "black", alpha = 0.7) +
      labs(title = paste("Histogram of", input$column),
           x = input$column,
           y = "Frequency")
  })
}

# Run the application
shinyApp(ui = ui, server = server)