This report analyzes storm data to determine which weather events are most harmful to population health and which cause the greatest economic damage in the United States.
data <- read.csv(“repdata-data-StormData.csv”)
library(dplyr)
storm_data <- data %>% select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
convert_exp <- function(exp) { if (exp %in% c(“K”, “k”)) return(1e3) else if (exp %in% c(“M”, “m”)) return(1e6) else if (exp %in% c(“B”, “b”)) return(1e9) else return(1) }
storm_data\(PROP_MULT <- sapply(storm_data\)PROPDMGEXP, convert_exp) storm_data\(CROP_MULT <- sapply(storm_data\)CROPDMGEXP, convert_exp)
storm_data\(PROP_TOTAL <- storm_data\)PROPDMG * storm_data\(PROP_MULT storm_data\)CROP_TOTAL <- storm_data\(CROPDMG * storm_data\)CROP_MULT
storm_data\(TOTAL_DAMAGE <- storm_data\)PROP_TOTAL + storm_data$CROP_TOTAL
health_impact <- storm_data %>% group_by(EVTYPE) %>% summarise(total_health = sum(FATALITIES + INJURIES, na.rm = TRUE)) %>% arrange(desc(total_health)) %>% head(10)
health_impact
barplot(health_impact\(total_health, names.arg = health_impact\)EVTYPE, las = 2, col = “red”, main = “Top 10 Most Harmful Weather Events”, ylab = “Total Injuries + Fatalities”)
economic_impact <- storm_data %>%
group_by(EVTYPE) %>% summarise(total_damage = sum(TOTAL_DAMAGE, na.rm = TRUE)) %>% arrange(desc(total_damage)) %>% head(10)
economic_impact
barplot(economic_impact\(total_damage, names.arg = economic_impact\)EVTYPE, las = 2, col = “blue”, main = “Top 10 Events by Economic Damage”, ylab = “Damage (USD)”)