Hi,
Please I need help to automate this process. I have multiple csv files for each pollutant. So for a folder called "C02", it has about 50 csv files ( each csv file corresponds to a year), the other pollutant have similar number of csv files. The attached is the code I have been using. I want to automate this ( for the csv files for each pollutant) since that is going to save time and resources.
#===== 1980 ======
hap1980 <- read.csv("daily_HAPS_1980.csv")
t80 <- hap1980[hap1980$State.Name %in% c("Michigan", "Ohio","Indiana","Pennsylvania") , c('State.Name','County.Code','County.Name', 'Longitude', 'Latitude','Arithmetic.Mean')]
cord <- c("Latitude", "Longitude")
t80$GrpHAP <- do.call(paste,c(t80[cord], sep=" , "))
tm80 <- t80 %>%
group_by(State.Name,County.Name,Latitude,Longitude, GrpHAP) %>%
summarise(Trimmed_mean= mean(Arithmetic.Mean, trim=0.1), Average = mean(Arithmetic.Mean))
write.csv(tm80,"path\Timmedmeans_1980.csv", row.names = FALSE)
#=========================== 1981 =================================
hap1981 <- read.csv("daily_HAPS_1981.csv")
t81 <- hap1981[hap1981$State.Name %in% c("Michigan", "Ohio","Indiana","Pennsylvania") , c('State.Name','County.Code','County.Name', 'Longitude', 'Latitude','Arithmetic.Mean')]
cord <- c("Latitude", "Longitude")
t81$GrpHAP <- do.call(paste,c(t81[cord], sep=" , "))
tm81 <- t81 %>%
group_by(State.Name,County.Name,Latitude,Longitude, GrpHAP) %>%
summarise(Trimmed_mean= mean(Arithmetic.Mean, trim=0.1), Average = mean(Arithmetic.Mean))
write.csv(tm81,"path\Timmedmeans_1981.csv", row.names = FALSE)
#=========================== 1982 =================================
hap1982 <- read.csv("daily_HAPS_1982.csv")
t82 <- hap1982[hap1982$State.Name %in% c("Michigan", "Ohio","Indiana","Pennsylvania") , c('State.Name','County.Code','County.Name', 'Longitude', 'Latitude','Arithmetic.Mean')]
cord <- c("Latitude", "Longitude")
t82$GrpHAP <- do.call(paste,c(t82[cord], sep=" , "))
tm82 <- t82 %>%
group_by(State.Name,County.Name,Latitude,Longitude, GrpHAP) %>%
summarise(Trimmed_mean= mean(Arithmetic.Mean, trim=0.1), Average = mean(Arithmetic.Mean))
write.csv(tm82,"path\Timmedmeans_1982.csv", row.names = FALSE)
#=========================== 1983 =================================
hap1983 <- read.csv("daily_HAPS_1983.csv")
t83 <- hap1983[hap1983$State.Name %in% c("Michigan", "Ohio","Indiana","Pennsylvania") , c('State.Name','County.Code','County.Name', 'Longitude', 'Latitude','Arithmetic.Mean')]
cord <- c("Latitude", "Longitude")
t83$GrpHAP <- do.call(paste,c(t83[cord], sep=" , "))
tm83 <- t83 %>%
group_by(State.Name,County.Name,Latitude,Longitude, GrpHAP) %>%
summarise(Trimmed_mean= mean(Arithmetic.Mean, trim=0.1), Average = mean(Arithmetic.Mean))
write.csv(tm83,"path\Timmedmeans_1983.csv", row.names = FALSE)