#Load library library(dplyr) #Set Working Path setwd(“C:/Users/bridg/OneDrive/Desktop/Collage/GIS-461/Final Exam/Maricopa”)

#list Station files downloaded from AZMAT files <-list.files(path=‘.’, pattern =“txt$”, full.names = TRUE) print(files) #Name columns so they can be singled out as there are no headers on the downloaded .txt files columns <-c(‘Year’, ‘Day’, ‘Hour’, ‘AirT_Max’, ‘AirT_Min’, ‘AirT_Mean’, ‘RH_Max’, ‘RH_Min’, ‘RH_Mean’, ‘VPD_Mean’, ‘SolarRad’, ‘Percip’, ‘4ST_Max’, ‘4ST_Min’, ‘4ST_Mean’, ‘20ST_Max’, ‘20ST_Min’, ‘20ST_Mean’, ‘WS_Mean’, ‘WS_VectorM’, ‘WS_VectorD’, ‘WDirec_SD’, ‘MaxWS’, ‘HeatUnit’, ‘ReferEvap’) # Assign column names data_list <- lapply(files, function(f) { df <- read.table(f, sep = “,”, header = FALSE) colnames(df) <- columns df })

Assign names based on the year in each file (2002–2022)

years <- 2002:2022 names(data_list) <- years

#Calculate Mean and SD for the Air Temperture Maximum year_mean <- numeric(length(years)) year_sd <- numeric(length(years))

for (i in seq_along(years)) { df <- data_list[[i]]

# Extract daily high temps Tmax <- df$AirT_Max

# Compute stats year_mean[i] <- mean(Tmax, na.rm = TRUE) year_sd[i] <- sd(Tmax, na.rm = TRUE) } #Create the summary results <- data.frame( Year = years, Avg_Daily_High_Temp = round(year_mean, 2), SD_Daily_High_Temp = round(year_sd, 2) )

print(results)

#Export summary as a .csv file write.csv(results, “Maricopa_2002_2022_TempSummary.csv”, row.names = FALSE)