Synopsis

The effects of weather events on local health and property is analyzed using the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database. Tornados, warm weather (i.e. heat), flood and high winds cause the largest number of fatalities and injuries across events. Heat and coastal storms are the deadliest per event. Hurricanes and heat are the most injurious per event. Floods, hurricanes, tornados and hazardous surf caused the most property damage. Excessively dry weather, floods, ice and hurricanes caused the most crop damage.

Environment

R version TK Patched (TK)
OS Microsoft Windows 8.1
Platform: Dell Inspiron 3521 BLUEICING (64-bit) Intel Pentium CPU 2127U@1.90GHz

Locale: en_US.UTF-8/ TK get this from command

attached base packages: stats graphics grDevices utils dfs base

other attached packages:

require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.1.1

loaded via a namespace (and not attached): NA

Version Control

local: Git Bash, ~/datasciencecoursera/ReproducibleResearch
remote: RPub.com/NJBlume

Data Processing

The data are imported below.

setwd("~/..")
setwd("datasciencecoursera/ReproducibleResearch")
d <- read.csv(file="repdata-data-StormData.csv", head=TRUE, sep=",", stringsAsFactors=FALSE)
df<-d[ , c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")]
df = as.data.frame(sapply(df, tolower))

EVTYPE describes the type of weather event that caused some type of damage. Misspellings and alternative terminology are fixed below. Some closely related events are also grouped.

df <- df[-grep("summary", df$EVTYPE), ]
df[grep("sleet", df$EVTYPE), "EVTYPE2"]<-"sleet"
df[grep("freezing", df$EVTYPE), "EVTYPE2"]<-"sleet"
df[grep("freeze", df$EVTYPE), "EVTYPE2"]<-"ice"
df[grep("frost", df$EVTYPE), "EVTYPE2"]<-"ice"
df[grep("ice", df$EVTYPE), "EVTYPE2"]<-"ice"
df[grep("icy", df$EVTYPE), "EVTYPE2"]<-"ice"
df[grep("avalance", df$EVTYPE), "EVTYPE2"]<-"avalanche"
df[grep("avalanche", df$EVTYPE), "EVTYPE2"]<-"avalanche"
df[grep("thunderstorm", df$EVTYPE), "EVTYPE2"]<-"thunderstorm"
df[grep("tstm", df$EVTYPE), "EVTYPE2"]<-"thunderstorm"
df[grep("dryness", df$EVTYPE), "EVTYPE2"]<-"excessively dry"
df[grep("dry", df$EVTYPE), "EVTYPE2"]<-"excessively dry"
df[grep("driest", df$EVTYPE), "EVTYPE2"]<-"excessively dry"
df[grep("low rainfall", df$EVTYPE), "EVTYPE2"]<-"excessively dry"
df[grep("drought", df$EVTYPE), "EVTYPE2"]<-"excessively dry"
df[grep("wind", df$EVTYPE), "EVTYPE2"]<-"wind"
df[grep("wnd", df$EVTYPE), "EVTYPE2"]<-"wind"
df[grep("snow", df$EVTYPE), "EVTYPE2"]<-"snow"
df[grep("flood", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("hot", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("heat", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("warmth", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("warm", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("high temp", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[df$EVTYPE == "high", "EVTYPE2"]<-"warm weather"
df[grep("record high", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("heatburst", df$EVTYPE), "EVTYPE2"]<-"warm weather"
df[grep("cold", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("low temp", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("record low", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("winter weather", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("wintry", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("wintery", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("cool", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("winter mix", df$EVTYPE), "EVTYPE2"]<-"cold weather"
df[grep("precip", df$EVTYPE), "EVTYPE2"]<-"rain"
df[grep("rain", df$EVTYPE), "EVTYPE2"]<-"rain"
df[grep("wet", df$EVTYPE), "EVTYPE2"]<-"rain"
df[grep("shower", df$EVTYPE), "EVTYPE2"]<-"rain"
df[grep("hail", df$EVTYPE), "EVTYPE2"]<-"hail"
df[grep("coastal erosion", df$EVTYPE), "EVTYPE2"]<-"rock slide"
df[grep("fog", df$EVTYPE), "EVTYPE2"]<-"fog"
df[grep("vog", df$EVTYPE), "EVTYPE2"]<-"fog"
df[grep("surf", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("swell", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("storm surge", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("red", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("sea", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("rogue wave", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("seiche", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("tide", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("wave", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("current", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("coastal surge", df$EVTYPE), "EVTYPE2"]<-"hazardous surf"
df[grep("flood", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("fldg", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("fld", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("stream", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("floooding", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("high water", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("rising water", df$EVTYPE), "EVTYPE2"]<-"flood"
df[grep("funnel", df$EVTYPE), "EVTYPE2"]<-"wall cloud/funnel cloud"
df[grep("wall cloud", df$EVTYPE), "EVTYPE2"]<-"wall cloud/funnel cloud"
df[grep("hurricane", df$EVTYPE), "EVTYPE2"]<-"hurricane"
df[grep("floyd", df$EVTYPE), "EVTYPE2"]<-"hurricane"
df[grep("smoke", df$EVTYPE), "EVTYPE2"]<-"smoke"
df[grep("volcanic", df$EVTYPE), "EVTYPE2"]<-"volcanic eruption"
df[grep("tornado", df$EVTYPE), "EVTYPE2"]<-"tornado"
df[grep("torndao", df$EVTYPE), "EVTYPE2"]<-"tornado"
df[grep("lightning", df$EVTYPE), "EVTYPE2"]<-"lightning"
df[grep("lighting", df$EVTYPE), "EVTYPE2"]<-"lightning"
df[grep("lignting", df$EVTYPE), "EVTYPE2"]<-"lightning"
df[grep("ligntning", df$EVTYPE), "EVTYPE2"]<-"lightning"
df[grep(" lightning", df$EVTYPE), "EVTYPE2"]<-"lightning"
df[grep("fire", df$EVTYPE), "EVTYPE2"]<-"wildfire"
df[grep("dust", df$EVTYPE), "EVTYPE2"]<-"blowing dust"
df[grep("blizzard", df$EVTYPE), "EVTYPE2"]<-"blizzard"
df[grep("fire", df$EVTYPE), "EVTYPE2"]<-"wildfire"
df[grep("slide", df$EVTYPE), "EVTYPE2"]<-"mud/rock slide"
df[grep("erosion", df$EVTYPE), "EVTYPE2"]<-"mud/rock slide"
df[grep("erosin", df$EVTYPE), "EVTYPE2"]<-"mud/rock slide"
df[grep("landslump", df$EVTYPE), "EVTYPE2"]<-"mud/rock slide"
df[grep("spout", df$EVTYPE), "EVTYPE2"]<-"waterspout"
df[grep("tropical storm", df$EVTYPE), "EVTYPE2"]<-"tropical storm"
df[grep("dam", df$EVTYPE), "EVTYPE2"]<-"dam failure"
df[grep("no severe", df$EVTYPE), "EVTYPE2"]<-"mild pattern"
df[grep("none", df$EVTYPE), "EVTYPE2"]<-"mild pattern"
df[grep("urban/small", df$EVTYPE), "EVTYPE2"]<-"mild pattern"
df[grep("urban and small", df$EVTYPE), "EVTYPE2"]<-"mild pattern"
df[grep("urban small", df$EVTYPE), "EVTYPE2"]<-"mild pattern"
df[grep("gustnado", df$EVTYPE), "EVTYPE2"]<-"gustnado"
df[grep("severe turbulence", df$EVTYPE), "EVTYPE2"]<-"other"
df[grep("microburst", df$EVTYPE), "EVTYPE2"]<-"other"
df[grep("downburst", df$EVTYPE), "EVTYPE2"]<-"other"
df[grep("metro storm", df$EVTYPE), "EVTYPE2"]<-"other"
df[grep("northern lights", df$EVTYPE), "EVTYPE2"]<-"other"
df[grep("marine", df$EVTYPE), "EVTYPE2"]<-"?"
df[df$EVTYPE == "coastalstorm", "EVTYPE2"]<-"coastal storm"
df[df$EVTYPE == "excessive", "EVTYPE2"]<-"?"
df[df$EVTYPE == "record temperatures", "EVTYPE2"]<-"?"
df[df$EVTYPE == "record temperature", "EVTYPE2"]<-"?"
df[df$EVTYPE == "temperature record", "EVTYPE2"]<-"?"
df[df$EVTYPE == "apache county", "EVTYPE2"]<-"?"
df[df$EVTYPE == "glaze", "EVTYPE2"]<-"?"
df[df$EVTYPE == "heavy mix", "EVTYPE2"]<-"?"
df[df$EVTYPE == "monthly temperature", "EVTYPE2"]<-"?"
df[df$EVTYPE == "drowning", "EVTYPE2"]<-"?"
df[df$EVTYPE == "southeast", "EVTYPE2"]<-"?"
df[df$EVTYPE == "hypothermia", "EVTYPE2"]<-"hypothermia/exposure"

Coding is tranlated for easier cost computation: “h” or “H” means 10^2, “k” or “K” means 10^3, “m” or “M” means 10^6 and “b” or “B” means 10^9.

df[df$PROPDMGEXP == "h", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "h", "PROPDMG"])) * 100
df[df$PROPDMGEXP == "k", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "k", "PROPDMG"])) * 1000
df[df$PROPDMGEXP == "m", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "m", "PROPDMG"])) * 10^6
df[df$PROPDMGEXP == "b", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "b", "PROPDMG"])) * 10^9
df[df$PROPDMGEXP == "1", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "1", "PROPDMG"])) * 10^1
df[df$PROPDMGEXP == "2", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "2", "PROPDMG"])) * 10^2
df[df$PROPDMGEXP == "3", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "3", "PROPDMG"])) * 10^3
df[df$PROPDMGEXP == "4", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "4", "PROPDMG"])) * 10^4
df[df$PROPDMGEXP == "5", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "5", "PROPDMG"])) * 10^5
df[df$PROPDMGEXP == "6", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "6", "PROPDMG"])) * 10^6
df[df$PROPDMGEXP == "7", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "7", "PROPDMG"])) * 10^7
df[df$PROPDMGEXP == "8", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "8", "PROPDMG"])) * 10^8
df[df$PROPDMGEXP == "9", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "9", "PROPDMG"])) * 10^9
df[df$PROPDMGEXP == "10", "newPROPDMG"] <- as.numeric(as.character(df[df$PROPDMGEXP == "10", "PROPDMG"])) * 10^10

df[df$CROPDMGEXP == "h", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "h", "CROPDMG"])) * 100
df[df$CROPDMGEXP == "k", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "k", "CROPDMG"])) * 1000
df[df$CROPDMGEXP == "m", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "m", "CROPDMG"])) * 10^6
df[df$CROPDMGEXP == "b", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "b", "CROPDMG"])) * 10^9
df[df$CROPDMGEXP == "1", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "1", "CROPDMG"])) * 10^1
df[df$CROPDMGEXP == "2", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "2", "CROPDMG"])) * 10^2
df[df$CROPDMGEXP == "3", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "3", "CROPDMG"])) * 10^3
df[df$CROPDMGEXP == "4", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "4", "CROPDMG"])) * 10^4
df[df$CROPDMGEXP == "5", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "5", "CROPDMG"])) * 10^5
df[df$CROPDMGEXP == "6", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "6", "CROPDMG"])) * 10^6
df[df$CROPDMGEXP == "7", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "7", "CROPDMG"])) * 10^7
df[df$CROPDMGEXP == "8", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "8", "CROPDMG"])) * 10^8
df[df$CROPDMGEXP == "9", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "9", "CROPDMG"])) * 10^9
df[df$CROPDMGEXP == "10", "newCROPDMG"] <- as.numeric(as.character(df[df$CROPDMGEXP == "10", "CROPDMG"])) * 10^10

Results

1. Across the United States, which types of events are most harmful with respect to population health?

Total number of deaths across all instances of a type of event, in rank order:

totfatal <- aggregate(as.numeric(as.character(FATALITIES))~EVTYPE2,data=df,FUN=sum)
colnames(totfatal)<- c("EventType", "TotFatalities")
totfatal$rank <- rank(-totfatal$TotFatalities)
totfatal <- totfatal[order(totfatal$rank,decreasing=F), ]
totfatal
##                  EventType TotFatalities rank
## 26                 tornado          5658  1.0
## 30            warm weather          2957  2.0
## 9                    flood          1556  3.0
## 33                    wind          1148  4.0
## 13          hazardous surf          1013  5.0
## 17               lightning           817  6.0
## 6             cold weather           514  7.0
## 2                avalanche           225  8.0
## 24                    snow           149  9.0
## 14               hurricane           135 10.0
## 21                    rain           115 11.0
## 16                     ice           104 12.0
## 3                 blizzard           101 13.0
## 32                wildfire            90 14.0
## 10                     fog            81 15.0
## 27          tropical storm            66 16.0
## 1                        ?            50 17.0
## 19          mud/rock slide            44 18.0
## 4             blowing dust            24 19.0
## 12                    hail            20 20.0
## 31              waterspout             6 21.0
## 22                   sleet             5 22.0
## 20                   other             3 23.0
## 5            coastal storm             1 25.5
## 15    hypothermia/exposure             1 25.5
## 18            mild pattern             1 25.5
## 25            thunderstorm             1 25.5
## 7              dam failure             0 30.5
## 8          excessively dry             0 30.5
## 11                gustnado             0 30.5
## 23                   smoke             0 30.5
## 28       volcanic eruption             0 30.5
## 29 wall cloud/funnel cloud             0 30.5
maxfatalevent <- totfatal[totfatal$rank == 1, "EventType"]
maxfatalcount <- totfatal[totfatal$rank == 1, "TotFatalities"]

secfatalevent <- totfatal[totfatal$rank == 2, "EventType"]
secfatalcount <- totfatal[totfatal$rank == 2, "TotFatalities"]

Total number of injuries across all instances of a type of event, in rank order:

totinjur <- aggregate(as.numeric(as.character(INJURIES))~EVTYPE2,data=df,FUN=sum)
colnames(totinjur)<- c("EventType", "TotInjuries")
totinjur$rank <- rank(-totinjur$TotInjuries)
totinjur <- totinjur[order(totinjur$rank,decreasing=F), ]
totinjur
##                  EventType TotInjuries rank
## 26                 tornado       91364  1.0
## 33                    wind       11235  2.0
## 30            warm weather        8833  3.0
## 9                    flood        8678  4.0
## 17               lightning        5232  5.0
## 16                     ice        2186  6.0
## 32                wildfire        1608  7.0
## 12                    hail        1467  8.0
## 14               hurricane        1328  9.0
## 13          hazardous surf        1264 10.0
## 24                    snow        1161 11.0
## 10                     fog        1077 12.0
## 6             cold weather         934 13.0
## 3                 blizzard         806 14.0
## 4             blowing dust         483 15.0
## 27          tropical storm         383 16.0
## 21                    rain         333 17.0
## 1                        ?         280 18.0
## 2                avalanche         170 19.0
## 31              waterspout          72 20.0
## 19          mud/rock slide          60 21.0
## 25            thunderstorm          39 22.0
## 20                   other          28 23.0
## 22                   sleet          15 24.0
## 7              dam failure           7 25.0
## 8          excessively dry           4 26.0
## 29 wall cloud/funnel cloud           3 27.0
## 5            coastal storm           0 30.5
## 11                gustnado           0 30.5
## 15    hypothermia/exposure           0 30.5
## 18            mild pattern           0 30.5
## 23                   smoke           0 30.5
## 28       volcanic eruption           0 30.5
maxinjurevent <- totinjur[totinjur$rank == 1, "EventType"]
maxinjurcount <- totinjur[totinjur$rank == 1, "TotInjuries"]
secinjurevent <- totinjur[totinjur$rank == 2, "EventType"]
secinjurcount <- totinjur[totinjur$rank == 2, "TotInjuries"]
ggplot(totinjur[1:10,], aes(EventType, TotInjuries, fill=EventType)) + geom_bar(stat = "identity")+  ylab("Total Number of Injuries")+ xlab("Event Type")+ ggtitle("Top Ten Types of Events Causing Injuries")+ theme(axis.text.x  = element_text(angle=30, vjust=0.5))

For harm done per event of a given type rather than across all instances of the type of event, the results are different. Some events are rarer but also more harmful to people’s health when they occur.

Mean number of deaths by type of event, in rank order:

meanfatal <- aggregate(as.numeric(as.character(FATALITIES))~EVTYPE2,data=df,FUN=mean)
colnames(meanfatal)<- c("EventType", "MeanFatalities")
meanfatal$rank <- rank(-meanfatal$MeanFatalities)
meanfatal <- meanfatal[order(meanfatal$rank,decreasing=F), ]
meanfatal
##                  EventType MeanFatalities rank
## 30            warm weather   1.0655855856  1.0
## 5            coastal storm   1.0000000000  2.5
## 15    hypothermia/exposure   1.0000000000  2.5
## 2                avalanche   0.5813953488  4.0
## 14               hurricane   0.4655172414  5.0
## 13          hazardous surf   0.3443235894  6.0
## 27          tropical storm   0.0946915352  7.0
## 26                 tornado   0.0932324880  8.0
## 19          mud/rock slide   0.0655737705  9.0
## 17               lightning   0.0517809608 10.0
## 22                   sleet   0.0515463918 11.0
## 6             cold weather   0.0480418731 12.0
## 10                     fog   0.0429936306 13.0
## 4             blowing dust   0.0408163265 14.0
## 3                 blizzard   0.0368075802 15.0
## 16                     ice   0.0286896552 16.0
## 32                wildfire   0.0212264151 17.0
## 9                    flood   0.0180778883 18.0
## 18            mild pattern   0.0147058824 19.0
## 20                   other   0.0133928571 20.0
## 25            thunderstorm   0.0109890110 21.0
## 21                    rain   0.0093291150 22.0
## 24                    snow   0.0084534211 23.0
## 1                        ?   0.0039252630 24.0
## 33                    wind   0.0032807874 25.0
## 31              waterspout   0.0015523933 26.0
## 12                    hail   0.0000689767 27.0
## 7              dam failure   0.0000000000 30.5
## 8          excessively dry   0.0000000000 30.5
## 11                gustnado   0.0000000000 30.5
## 23                   smoke   0.0000000000 30.5
## 28       volcanic eruption   0.0000000000 30.5
## 29 wall cloud/funnel cloud   0.0000000000 30.5
maxfatalevent <- meanfatal[meanfatal$rank == 1, "EventType"]
maxfatalcount <- meanfatal[meanfatal$rank == 1, "MeanFatalities"]
secfatalevent <- meanfatal[meanfatal$rank == 2, "EventType"]
secfatalcount <- meanfatal[meanfatal$rank == 2, "MeanFatalities"]

Mean number of injuries by type of event, in rank order:

meaninjur <- aggregate(as.numeric(as.character(INJURIES))~EVTYPE2,data=df,FUN=mean)
colnames(meaninjur)<- c("EventType", "MeanInjuries")
meaninjur$rank <- rank(-meaninjur$MeanInjuries)
meaninjur <- meaninjur[order(meaninjur$rank,decreasing=F), ]
meaninjur
##                  EventType MeanInjuries rank
## 14               hurricane 4.5793103448  1.0
## 30            warm weather 3.1830630631  2.0
## 26                 tornado 1.5054954109  3.0
## 4             blowing dust 0.8214285714  4.0
## 16                     ice 0.6030344828  5.0
## 10                     fog 0.5716560510  6.0
## 27          tropical storm 0.5494978479  7.0
## 2                avalanche 0.4392764858  8.0
## 13          hazardous surf 0.4296397009  9.0
## 25            thunderstorm 0.4285714286 10.0
## 32                wildfire 0.3792452830 11.0
## 17               lightning 0.3316009634 12.0
## 3                 blizzard 0.2937317784 13.0
## 22                   sleet 0.1546391753 14.0
## 7              dam failure 0.1272727273 15.0
## 20                   other 0.1250000000 16.0
## 9                    flood 0.1008225672 17.0
## 19          mud/rock slide 0.0894187779 18.0
## 6             cold weather 0.0872978783 19.0
## 24                    snow 0.0658686032 20.0
## 33                    wind 0.0321077058 21.0
## 21                    rain 0.0270138720 22.0
## 1                        ? 0.0219814728 23.0
## 31              waterspout 0.0186287193 24.0
## 12                    hail 0.0050594407 25.0
## 8          excessively dry 0.0015847861 26.0
## 29 wall cloud/funnel cloud 0.0004285102 27.0
## 5            coastal storm 0.0000000000 30.5
## 11                gustnado 0.0000000000 30.5
## 15    hypothermia/exposure 0.0000000000 30.5
## 18            mild pattern 0.0000000000 30.5
## 23                   smoke 0.0000000000 30.5
## 28       volcanic eruption 0.0000000000 30.5
maxinjurevent <- meaninjur[meaninjur$rank == 1, "EventType"]
maxinjurcount <- meaninjur[meaninjur$rank == 1, "MeanInjuries"]
secinjurevent <- meaninjur[meaninjur$rank == 2, "EventType"]
secinjurcount <- meaninjur[meaninjur$rank == 2, "MeanInjuries"]

2. Across the United States, which types of events have the greatest economic consequences?

Total damage to property:

totpropdamage <- aggregate(newPROPDMG~EVTYPE2,data=df,FUN=sum)
colnames(totpropdamage)<- c("EventType", "TotPropDamage")
totpropdamage$rank <- rank(-totpropdamage$TotPropDamage)
totpropdamage <- totpropdamage[order(totpropdamage$rank,decreasing=F), ]
totpropdamage
##                  EventType TotPropDamage rank
## 8                    flood  168219697920    1
## 13               hurricane   84756180010    2
## 24                 tornado   58552152230    3
## 12          hazardous surf   48103512550    4
## 31                    wind   16056882630    5
## 11                    hail   16022837220    6
## 30                wildfire    8501628500    7
## 25          tropical storm    7714390550    8
## 14                     ice    3970045510    9
## 19                    rain    3237520690   10
## 23            thunderstorm    1208461550   11
## 7          excessively dry    1046106000   12
## 22                    snow    1011999740   13
## 15               lightning     935737780   14
## 3                 blizzard     664913950   15
## 17          mud/rock slide     379548100   16
## 5             cold weather     273889900   17
## 29              waterspout      60737700   18
## 9                      fog      25011500   19
## 6              dam failure      10351000   20
## 1                        ?       9936740   21
## 28            warm weather       9665700   22
## 18                   other       7349600   23
## 4             blowing dust       6337630   24
## 2                avalanche       3721800   25
## 26       volcanic eruption        500000   26
## 27 wall cloud/funnel cloud        199600   27
## 20                   sleet        145000   28
## 10                gustnado        102050   29
## 21                   smoke        100000   30
## 16            mild pattern         61100   31
maxevent <- totpropdamage[totpropdamage$rank == 1, "EventType"]
maxcount <- totpropdamage[totpropdamage$rank == 1, "TotPropDamage"]
secevent <- totpropdamage[totpropdamage$rank == 2, "EventType"]
seccount <- totpropdamage[totpropdamage$rank == 2, "TotPropDamage"]

Total damage to crops:

totcropdamage <- aggregate(newCROPDMG~EVTYPE2,data=df,FUN=sum)
colnames(totcropdamage)<- c("EventType", "TotCropDamage")
totcropdamage$rank <- rank(-totcropdamage$TotCropDamage)
totcropdamage <- totcropdamage[order(totcropdamage$rank,decreasing=F), ]
totcropdamage
##                  EventType TotCropDamage rank
## 7          excessively dry   13972566000    1
## 8                    flood   12388597200    2
## 14                     ice    6722945300    3
## 13               hurricane    5515292800    4
## 11                    hail    3111712850    5
## 30                    wind    1960859050    6
## 5             cold weather    1335623000    7
## 18                    rain    1007662800    8
## 27            warm weather     898869280    9
## 24          tropical storm     694896000   10
## 23                 tornado     417461360   11
## 29                wildfire     403281630   12
## 6              dam failure     296285000   13
## 21                    snow     134663100   14
## 3                 blizzard     112060000   15
## 12          hazardous surf      48107500   16
## 16          mud/rock slide      20017000   17
## 22            thunderstorm      18205000   18
## 15               lightning      12097090   19
## 4             blowing dust       3600000   20
## 1                        ?         50000   21
## 17                   other         15000   22
## 10                gustnado          1550   23
## 2                avalanche             0   27
## 9                      fog             0   27
## 19                   sleet             0   27
## 20                   smoke             0   27
## 25       volcanic eruption             0   27
## 26 wall cloud/funnel cloud             0   27
## 28              waterspout             0   27
maxevent <- totcropdamage[totcropdamage$rank == 1, "EventType"]
maxcount <- totcropdamage[totcropdamage$rank == 1, "TotCropDamage"]
secevent <- totcropdamage[totcropdamage$rank == 2, "EventType"]
seccount <- totcropdamage[totcropdamage$rank == 2, "TotCropDamage"]