Storms and other severe weather events can cause both public health and economic problems for communities and municipalities. Many severe events can result in fatalities, injuries, and property damage, and preventing such outcomes to the extent possible is a key concern.
This project involves exploring the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. This database tracks characteristics of major storms and weather events in the United States, including when and where they occur, as well as estimates of any fatalities, injuries, and property damage.
In this report,effect of weather events on personal as well as property damages was studied. Barplots were plotted seperately for the top 10 weather events that causes highest fatalities and highest injuries. Results indicate that most Fatalities and injuries were caused by Tornados.Also, barplots were plotted for the top 10 weather events that causes the highest property damage and crop damage.
I read the data and then got only the columns i need.
dt<- read.csv("repdata-data-StormData.csv")
project_data <- c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
dt<-dt[,project_data]
Then i made a function to get the exponent value of the damage and use it to find that for each property.Lastly, I found the total damage for each property.
library(plyr);options(scipen=999)
getE <- function(e) {
if (e %in% c("h", "H"))
return(2)
else if (e %in% c("k", "K"))
return(3)
else if (e %in% c("m", "M"))
return(6)
else if (e %in% c("b", "B"))
return(9)
else if (!is.na(as.numeric(e)))
return(as.numeric(e))
else if (e %in% c("", "-", "?", "+"))
return(0)
else {
stop("Invalid value.")
}
}
pe<-sapply(dt$PROPDMGEXP,getE)
ce<-sapply(dt$CROPDMGEXP,getE)
dt$PDMG<-dt$PROPDMG*(10**pe)
dt$CDMG<-dt$CROPDMG*(10**ce)
Using ddply i found the total fatalities, injuries and total damage for each event.
ppl<-ddply(dt,.(EVTYPE),summarize,"Fatalities"=sum(FATALITIES),"Injuries"=sum(INJURIES))
econ<-ddply(dt,.(EVTYPE),summarize,"Property"=sum(PDMG),"Crops"=sum(CDMG))
econ$'Total Damage'<-econ$Propert+econ$Crops
I sorted the results and got the first 10 events with the most damage in fatalities and injuries and the 5 first events with the most economical damage.
inj<-ppl[order(ppl$Injuries,decreasing = T),]
inj<-inj[1:10,]
fat<-ppl[order(ppl$Fatalities,decreasing = T),]
fat<-fat[1:10,]
ec<-econ[order(econ$'Total Damage',decreasing=T),]
ec<-ec[1:5,]
ec$'Total Damage'<-(ec$'Total Damage')/(10^9)
SO i plotted the first 10 events with the most damage in fatalities and injuries and the 5 first events with the most economical damage.
barplot(inj$Injuries,names.arg = inj$EVTYPE,
main="Events with Highest Injuries",col="orange",cex.names = .75)
inj$EVTYPE
## [1] TORNADO TSTM WIND FLOOD
## [4] EXCESSIVE HEAT LIGHTNING HEAT
## [7] ICE STORM FLASH FLOOD THUNDERSTORM WIND
## [10] HAIL
## 985 Levels: HIGH SURF ADVISORY COASTAL FLOOD ... WND
barplot(fat$Fatalities,names.arg = fat$EVTYPE,
main="Events with Highest Mortality",col="red",cex.names = .75)
fat$EVTYPE
## [1] TORNADO EXCESSIVE HEAT FLASH FLOOD HEAT
## [5] LIGHTNING TSTM WIND FLOOD RIP CURRENT
## [9] HIGH WIND AVALANCHE
## 985 Levels: HIGH SURF ADVISORY COASTAL FLOOD ... WND
As we can see Tornado caused the most injuries and the most deaths. After that were Excessive Heat for fatalities and Thunderstorm for injuries.
barplot(ec$'Total Damage',names.arg = ec$EVTYPE,
main="Events with Highest Economical Damage(in Billions)",col="green",cex.names=.75)
ec$EVTYPE
## [1] FLASH FLOOD THUNDERSTORM WINDS TORNADO
## [4] HAIL LIGHTNING
## 985 Levels: HIGH SURF ADVISORY COASTAL FLOOD ... WND
Flash flood caused the most economical damages and after that were Thunderstorm winds.