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.

Synopsis

This analysis is based on the data provided by NOAA storm database. In a sense, the storm weather may be introduced the major impact for the Economic of the country. It is because the storm will come with the flooding, and the most of the time it will bring major damage to the suffered areas. However, the major bad weather event is tornado in U.S., especially the area in Tornado Alley(https://en.wikipedia.org/wiki/Tornado_Alley). Moreover, other weather events will be analyzed. In which, include ‘excessive heat’, ‘ice storm’, ‘thunderstorm wind’, and so on. The analyzed will be focused on the number of deaths and the number of injuries affected by the store or other extremely weather.

R Additional Library
library(ggplot2)  
library(plyr)  
library(reshape2) 
sessionInfo()
## R version 3.2.2 (2015-08-14)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: OS X 10.11.4 (El Capitan)
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] reshape2_1.4.1 plyr_1.8.3     ggplot2_2.1.0 
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.3      digest_0.6.9     grid_3.2.2       gtable_0.2.0    
##  [5] formatR_1.2.1    magrittr_1.5     evaluate_0.8     scales_0.4.0    
##  [9] stringi_1.0-1    rmarkdown_0.9.5  tools_3.2.2      stringr_1.0.0   
## [13] munsell_0.4.3    yaml_2.1.13      colorspace_1.2-6 htmltools_0.3   
## [17] knitr_1.12.3

Data Processing

The analysis was performed on Storm Events Database, provided by National Climatic Data Center. The data is from a comma-separated-value file available here. There is also some documentation of the data available here.

The first step is to read the data into a data frame.

rawdata <- read.csv(bzfile("/Users/jackmok1/Downloads/repdata-data-StormData.csv.bz2"))
stormdata <- subset(rawdata, select = c("EVTYPE","FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", "CROPDMGEXP")
                   )
# Define the Standard events
standevent <- c(
"Astronomical Low Tide","Avalanche", "Blizzard",      "Coastal Flood","Cold/Wind Chill", "Debris Flow","Dense Fog",
"Dense Smoke",          "Drought",   "Dust Devil",    "Dust Storm",   "Excessive Heat",  "Extreme Cold/Wind Chill",
"Flash Flood",          "Flood",      "Frost/Freeze", "Funnel Cloud", "Freezing Fog",    "Hail",     "Heat",
"Heavy Rain",           "Heavy Snow", "High Surf",    "High Wind",     "Hurricane",      "Ice Storm",    
"Lake-Effect Snow",     "Lakeshore Flood",  "Lightning",    "Marine Hail",    "Marine High Wind",   "Marine Strong Wind",   
"Marine Thunderstorm Wind",   "Rip Current",  "Seiche",     "Sleet",      "Storm Surge/Tide",  "Strong Wind",
"Thunderstorm Wind",   "Tornado",  "Tropical Depression",   "Tropical Storm",   "Tsunami",    "Volcanic Ash",   "Waterspout",    "Wildfire",    "Winter Storm",   "Winter Weather");
standevent <- sort(tolower(standevent));

Data Cleansing

Some Events type (EVTYPE) are similar such as “SNOW” and “SNOW/ICE” , and there are some event types are saved as upper letter and some as lower letter. The Cleansing Steps :

Standardize Event Types

lower_event_types <- tolower(stormdata$EVTYPE);
unique_lower_event_types <- length(unique(lower_event_types));
# Update all event types with lower characters
stormdata$EVTYPE <- lower_event_types;

Refer to the Storm Data Event Table in Section 2.1.1 (https://d396qusza40orc.cloudfront.net/repdata%2Fpeer2_doc%2Fpd01016005curr.pdf) , there are 48 unique event types, however, there are 898 in the dataset. Therefore, the further cleansing for event type is performed as :

  • Check each patten and try to convert to standard name for 48 standard events.
cleandata <- data.frame();

for (event in standevent) {
 
  if (event != "flood" && event != "coastal flood" && event != "flash flood" && event != "lakeshore flood") {
     transitdata <- stormdata[grepl(event,stormdata$EVTYPE),]
     uniq_event <- unique(transitdata$EVTYPE);
     if (length(uniq_event) > 1) { 
       print(paste("The following events will be standardized by replacing :",event));
       print(uniq_event[2:length(uniq_event)]);
     }
     
     transitdata$EVTYPE[grepl(event,transitdata$EVTYPE)] <- event
  
     cleandata <- rbind(cleandata, transitdata)
  }
}
## [1] "The following events will be standardized by replacing : avalanche"
## [1] "heavy snow/blizzard/avalanche"
## [1] "The following events will be standardized by replacing : blizzard"
##  [1] "blizzard weather"               "high wind/blizzard"            
##  [3] "high wind/blizzard/freezing ra" "high wind/ blizzard"           
##  [5] "blizzard/high wind"             "high wind/wind chill/blizzard" 
##  [7] "blizzard/heavy snow"            "ground blizzard"               
##  [9] "heavy snow/blizzard"            "blizzard/freezing rain"        
## [11] "blizzard and heavy snow"        "blizzard and extreme wind chil"
## [13] "blizzard/winter storm"          "heavy snow/blizzard/avalanche" 
## [15] "blizzard summary"               "icestorm/blizzard"             
## [1] "The following events will be standardized by replacing : cold/wind chill"
## [1] "cold/wind chill"
## [1] "The following events will be standardized by replacing : dense fog"
## [1] "patchy dense fog"
## [1] "The following events will be standardized by replacing : drought"
## [1] "drought/excessive heat" "snow drought"          
## [3] "heat wave drought"      "heat/drought"          
## [5] "heat drought"           "excessive heat/drought"
## [1] "The following events will be standardized by replacing : dust devil"
## [1] "dust devil waterspout"
## [1] "The following events will be standardized by replacing : dust storm"
## [1] "high winds dust storm" "dust storm/high winds"
## [1] "The following events will be standardized by replacing : excessive heat"
## [1] "drought/excessive heat" "record/excessive heat" 
## [3] "excessive heat/drought"
## [1] "The following events will be standardized by replacing : funnel cloud"
## [1] "wall cloud/funnel cloud" "funnel clouds"          
## [3] "funnel cloud/hail"       "funnel cloud."          
## [5] "waterspout funnel cloud"
## [1] "The following events will be standardized by replacing : hail"
##  [1] "thunderstorm winds/hail"    "thunderstorm winds hail"   
##  [3] "hail 1.75)"                 "hail storm"                
##  [5] "hail 75"                    "tornadoes, tstm wind, hail"
##  [7] "small hail"                 "hail 80"                   
##  [9] "funnel cloud/hail"          "hail 0.75"                 
## [11] "hail 1.00"                  "hail/winds"                
## [13] "hail/wind"                  "hail 1.75"                 
## [15] "wind/hail"                  "thunderstorm winds/ hail"  
## [17] "hail 225"                   "hail 0.88"                 
## [19] "deep hail"                  "hail 88"                   
## [21] "hail 175"                   "hail 100"                  
## [23] "hail 150"                   "hail 075"                  
## [25] "hail 125"                   "hail 200"                  
## [27] "hail flooding"              "hail damage"               
## [29] "thunderstorm hail"          "hail 088"                  
## [31] "thunderstorm windshail"     "hail/icy roads"            
## [33] "hail aloft"                 "thunderstorm wind/hail"    
## [35] "hail 275"                   "hail 450"                  
## [37] "hailstorm"                  "hailstorms"                
## [39] "tstm wind/hail"             "hail(0.75)"                
## [41] "gusty wind/hail"            "late season hail"          
## [43] "non severe hail"            "marine hail"               
## [1] "The following events will be standardized by replacing : heat"
##  [1] "extreme heat"           "excessive heat"        
##  [3] "record heat"            "heat wave"             
##  [5] "drought/excessive heat" "record heat wave"      
##  [7] "record/excessive heat"  "heat waves"            
##  [9] "heat wave drought"      "heat/drought"          
## [11] "heat drought"           "heatburst"             
## [13] "excessive heat/drought"
## [1] "The following events will be standardized by replacing : heavy rain"
##  [1] "heavy rains"                    "lightning and heavy rain"      
##  [3] "heavy rain/lightning"           "lightning/heavy rain"          
##  [5] "high winds heavy rains"         "high winds/heavy rain"         
##  [7] "flooding/heavy rain"            "heavy rain/flooding"           
##  [9] "heavy rain/snow"                "heavy rain/severe weather"     
## [11] "thunderstorm winds/heavy rain"  "heavy rain and flood"          
## [13] "flash flood - heavy rain"       "flash flood/heavy rain"        
## [15] "heavy rain; urban flood winds;" "heavy rains/flooding"          
## [17] "heavy rain/mudslides/flood"     "heavy rainfall"                
## [19] "thunderstorm winds heavy rain"  "flood & heavy rain"            
## [21] "heavy rain/urban flood"         "heavy rain/small stream urban" 
## [23] "heavy rain and wind"            "heavy rain/high surf"          
## [25] "heavy rain/wind"                "tstm heavy rain"               
## [27] "locally heavy rain"             "heavy rain effects"            
## [1] "The following events will be standardized by replacing : heavy snow"
##  [1] "high wind and heavy snow"       "heavy snow/high"               
##  [3] "heavy snow/high winds/freezing" "high wind/heavy snow"          
##  [5] "heavy snow/wind"                "heavy snowpack"                
##  [7] "blizzard/heavy snow"            "heavy snow/high winds"         
##  [9] "heavy snow/high wind"           "heavy snow/blowing snow"       
## [11] "snow and heavy snow"            "snow/heavy snow"               
## [13] "heavy snow/blizzard"            "heavy snow/sleet"              
## [15] "heavy snow/ice storm"           "heavy snow and ice storm"      
## [17] "heavy snow/freezing rain"       "blizzard and heavy snow"       
## [19] "heavy snow and ice"             "heavy snow andblowing snow"    
## [21] "heavy snow/ice"                 "heavy snow/winter storm"       
## [23] "heavy snow and high winds"      "heavy snow/high winds & flood" 
## [25] "heavy snow squalls"             "heavy snow/squalls"            
## [27] "heavy snow-squalls"             "heavy snow   freezing rain"    
## [29] "heavy snow & ice"               "heavy snow/blizzard/avalanche" 
## [31] "heavy snow and strong winds"    "heavy snow and"                
## [33] "heavy snow shower"             
## [1] "The following events will be standardized by replacing : high surf"
## [1] "heavy rain/high surf"  "high surf advisory"    "   high surf advisory"
## [4] "high surf advisories"  "heavy surf/high surf" 
## [1] "The following events will be standardized by replacing : high wind"
##  [1] "high winds"                     "high wind"                     
##  [3] "high wind/blizzard"             "high wind and high tides"      
##  [5] "high wind/blizzard/freezing ra" "high wind and heavy snow"      
##  [7] "record cold and high wind"      "high winds heavy rains"        
##  [9] "high wind/ blizzard"            "blizzard/high wind"            
## [11] "high wind/low wind chill"       "high winds and wind chill"     
## [13] "heavy snow/high winds/freezing" "wind chill/high wind"          
## [15] "high wind/wind chill/blizzard"  "high wind/wind chill"          
## [17] "high wind/heavy snow"           "high wind/seas"                
## [19] "high winds/heavy rain"          "winter storm/high wind"        
## [21] "winter storm/high winds"        "high winds dust storm"         
## [23] "winter storm high winds"        "high wind damage"              
## [25] "high winds 57"                  "high winds 66"                 
## [27] "high winds 76"                  "high winds 63"                 
## [29] "high winds 67"                  "heavy snow/high winds"         
## [31] "high winds 82"                  "high winds 80"                 
## [33] "high winds 58"                  "high winds 73"                 
## [35] "high winds 55"                  "high winds/flooding"           
## [37] "heavy snow/high wind"           "high winds/"                   
## [39] "snow- high wind- wind chill"    "high wind 63"                  
## [41] "high winds/coastal flood"       "dust storm/high winds"         
## [43] "heavy snow and high winds"      "heavy snow/high winds & flood" 
## [45] "high wind 70"                   "high winds/cold"               
## [47] "snow/high winds"                "high winds/snow"               
## [49] "high wind and seas"             "high wind 48"                  
## [51] "high wind (g40)"                "marine high wind"              
## [1] "The following events will be standardized by replacing : hurricane"
## [1] "hurricane erin"             "hurricane opal"            
## [3] "hurricane"                  "hurricane-generated swells"
## [5] "hurricane emily"            "hurricane gordon"          
## [7] "hurricane felix"            "hurricane edouard"         
## [9] "hurricane/typhoon"         
## [1] "The following events will be standardized by replacing : ice storm"
## [1] "ice storm"                "sleet/ice storm"         
## [3] "snow and ice storm"       "heavy snow/ice storm"    
## [5] "heavy snow and ice storm" "ice storm and snow"      
## [7] "glaze/ice storm"          "snow/ice storm"          
## [1] "The following events will be standardized by replacing : lightning"
##  [1] "thunderstorm winds lightning"   "lightning and heavy rain"      
##  [3] "heavy rain/lightning"           "lightning/heavy rain"          
##  [5] "lightning thunderstorm windss"  "lightning thunderstorm winds"  
##  [7] "lightning injury"               "lightning and thunderstorm win"
##  [9] "thunderstorm wind/lightning"    "lightning."                    
## [11] "lightning fire"                 "lightning damage"              
## [13] "lightning and winds"            "lightning  wauseon"            
## [15] "tstm wind and lightning"        " lightning"                    
## [1] "The following events will be standardized by replacing : rip current"
## [1] "rip currents heavy surf" "rip currents/heavy surf"
## [3] "rip currents"           
## [1] "The following events will be standardized by replacing : sleet"
##  [1] "light snow and sleet"          "freezing rain and sleet"      
##  [3] "sleet/rain/snow"               "snow/rain/sleet"              
##  [5] "snow/sleet/freezing rain"      "sleet/ice storm"              
##  [7] "freezing rain/sleet"           "heavy snow/sleet"             
##  [9] "snow/sleet"                    "freezing rain sleet and"      
## [11] "freezing rain sleet and light" "sleet & freezing rain"        
## [13] "snow sleet"                    "sleet/snow"                   
## [15] "snow/sleet/rain"               "sleet/freezing rain"          
## [17] "snow and sleet"                "sleet storm"                  
## [1] "The following events will be standardized by replacing : strong wind"
## [1] "strong wind"                 "ice/strong winds"           
## [3] "heavy snow and strong winds" "strong wind gust"           
## [5] "flood/strong wind"           "marine strong wind"         
## [1] "The following events will be standardized by replacing : thunderstorm wind"
##  [1] "thunderstorm wind"              "thunderstorm winds lightning"  
##  [3] "thunderstorm winds/hail"        "thunderstorm winds hail"       
##  [5] "thunderstorm winds/funnel clou" "severe thunderstorm winds"     
##  [7] "lightning thunderstorm windss"  "thunderstorm winds 60"         
##  [9] "thunderstorm windss"            "lightning thunderstorm winds"  
## [11] "thunderstorm winds53"           "thunderstorm winds 13"         
## [13] "thunderstorm winds urban flood" "thunderstorm winds small strea"
## [15] "thunderstorm winds 2"           "thunderstorm winds 61"         
## [17] "thunderstorm winds/ hail"       "thunderstorm wind/lightning"   
## [19] "thunderstorm wind g50"          "thunderstorm winds/heavy rain" 
## [21] "thunderstorm winds      le cen" "thunderstorm winds g"          
## [23] "thunderstorm wind g60"          "thunderstorm winds."           
## [25] "thunderstorm wind g55"          "thunderstorm winds g60"        
## [27] "thunderstorm winds funnel clou" "thunderstorm winds 62"         
## [29] "thunderstorm winds/flash flood" "thunderstorm winds 53"         
## [31] "thunderstorm wind 59"           "thunderstorm wind 52"          
## [33] "thunderstorm wind 69"           "thunderstorm wind 60 mph"      
## [35] "thunderstorm wind 65mph"        "thunderstorm wind/ trees"      
## [37] "thunderstorm wind/awning"       "thunderstorm wind 98 mph"      
## [39] "thunderstorm wind trees"        "thunderstorm wind 59 mph"      
## [41] "thunderstorm winds 63 mph"      "thunderstorm wind/ tree"       
## [43] "thunderstorm wind 65 mph"       "thunderstorm wind."            
## [45] "thunderstorm wind 59 mph."      "thunderstorm windshail"        
## [47] "thunderstorm winds and"         "thunderstorm winds 50"         
## [49] "thunderstorm wind g52"          "thunderstorm winds 52"         
## [51] "thunderstorm wind g51"          "thunderstorm wind g61"         
## [53] "thunderstorm winds/flooding"    "thunderstorm wind 50"          
## [55] "thunderstorm wind 56"           "thunderstorm wind/hail"        
## [57] "thunderstorm winds/ flood"      "thunderstorm winds heavy rain" 
## [59] "thunderstorm wind (g40)"        "gusty thunderstorm winds"      
## [61] "gusty thunderstorm wind"        "marine thunderstorm wind"      
## [1] "The following events will be standardized by replacing : tornado"
##  [1] "tornado f0"                 "tornados"                  
##  [3] "waterspout/tornado"         "waterspout tornado"        
##  [5] "waterspout-tornado"         "tornadoes, tstm wind, hail"
##  [7] "cold air tornado"           "waterspout/ tornado"       
##  [9] "tornado f3"                 "tornado f1"                
## [11] "tornado/waterspout"         "tornado f2"                
## [13] "tornadoes"                  "tornado debris"            
## [1] "The following events will be standardized by replacing : tropical storm"
## [1] "tropical storm"        "tropical storm gordon" "tropical storm jerry" 
## [4] "tropical storm dean"  
## [1] "The following events will be standardized by replacing : volcanic ash"
## [1] "volcanic ash plume" "volcanic ashfall"  
## [1] "The following events will be standardized by replacing : waterspout"
##  [1] "waterspout/tornado"      "waterspouts"            
##  [3] "waterspout tornado"      "waterspout-tornado"     
##  [5] "waterspout-"             "waterspout/ tornado"    
##  [7] "dust devil waterspout"   "waterspout/"            
##  [9] "tornado/waterspout"      "waterspout funnel cloud"
## [11] " waterspout"            
## [1] "The following events will be standardized by replacing : wildfire"
## [1] "wildfires"
## [1] "The following events will be standardized by replacing : winter storm"
## [1] "winter storm/high wind"  "winter storm/high winds"
## [3] "winter storm high winds" "winter storms"          
## [5] "heavy snow/winter storm" "blizzard/winter storm"  
## [1] "The following events will be standardized by replacing : winter weather"
## [1] "winter weather mix" "winter weather/mix"
# Handling for Special flood events
coastal_flood_event <- c("coastal flood","coastal flooding", "high winds/coastal flood",
                 "beach erosion/coastal flood"," coastal flood",   "coastal  flooding/erosion", "coastal flooding/erosion",
                 "heavy surf coastal flooding","high winds/coastal flood"
                 )
for (event in coastal_flood_event) {
    transitdata <- stormdata[grepl(event,stormdata$EVTYPE),];
    transitdata$EVTYPE[grepl(event,transitdata$EVTYPE)] <- "coastal FLOOD";
    stormdata$EVTYPE[grepl(event,stormdata$EVTYPE)] <- "coastal FLOOD";
    cleandata <- rbind(cleandata, transitdata);
}    

# Flash Flood Event
transitdata <- stormdata[grepl("flash",stormdata$EVTYPE),];
transitdata$EVTYPE[grepl("flash",transitdata$EVTYPE)] <- "flash FLOOD";
stormdata$EVTYPE[grepl("flash",stormdata$EVTYPE)] <- "flash FLOOD";
cleandata <- rbind(cleandata, transitdata);

# Lakeshore Flood Event
transitdata <- stormdata[grepl("lakeshore flood",stormdata$EVTYPE),];
transitdata$EVTYPE[grepl("lakeshore flood",transitdata$EVTYPE)] <- "lakeshore FLOOD";
stormdata$EVTYPE[grepl("lakeshore flood",stormdata$EVTYPE)] <- "lakeshore FLOOD";
cleandata <- rbind(cleandata, transitdata);
       
#ice storm Event
transitdata <- stormdata[grepl("ice storm/flash flood",stormdata$EVTYPE),];
transitdata$EVTYPE[grepl("ice storm/flash flood",transitdata$EVTYPE)] <- "ice storm";
stormdata$EVTYPE[grepl("ice storm/flash flood",stormdata$EVTYPE)] <- "ice storm";
cleandata <- rbind(cleandata, transitdata);

#thunderstorm winds/flash flood" Event
transitdata <- stormdata[grepl("thunderstorm winds/flash flood",stormdata$EVTYPE),];
transitdata$EVTYPE[grepl("thunderstorm winds/flash flood",transitdata$EVTYPE)] <- "thunderstorm wind";
stormdata$EVTYPE[grepl("thunderstorm winds/flash flood",stormdata$EVTYPE)] <- "thunderstorm wind";
cleandata <- rbind(cleandata, transitdata);

# Handling for Flood events
transitdata <- stormdata[grepl("flood",stormdata$EVTYPE),]
uniq_event <- unique(transitdata$EVTYPE);
if (length(uniq_event) > 1) { 
       print(paste("The following events will be standardized by replacing :","flood"));
       print(uniq_event[2:length(uniq_event)]);
}
## [1] "The following events will be standardized by replacing : flood"
##  [1] "flood"                          "breakup flooding"              
##  [3] "river flood"                    "flood watch/"                  
##  [5] "flooding/heavy rain"            "urban flooding"                
##  [7] "urban/small flooding"           "local flood"                   
##  [9] "flood/rain/winds"               "urban/small stream flooding"   
## [11] "stream flooding"                "flood/rain/wind"               
## [13] "small stream urban flood"       "urban flood"                   
## [15] "heavy rain/flooding"            "high winds/flooding"           
## [17] "urban/small stream flood"       "minor flooding"                
## [19] "urban/small stream  flood"      "urban and small stream flood"  
## [21] "small stream flooding"          "floods"                        
## [23] "small stream and urban floodin" "small stream/urban flood"      
## [25] "small stream and urban flood"   "rural flood"                   
## [27] "thunderstorm winds urban flood" "major flood"                   
## [29] "ice jam flooding"               "street flood"                  
## [31] "small stream flood"             "lake flood"                    
## [33] "urban and small stream floodin" "river and stream flood"        
## [35] "minor flood"                    "river flooding"                
## [37] "flood/river flood"              "mud slides urban flooding"     
## [39] "heavy snow/high winds & flood"  "hail flooding"                 
## [41] "heavy rain and flood"           "coastal/tidal flood"           
## [43] "heavy rain; urban flood winds;" "tidal flood"                   
## [45] "heavy rains/flooding"           "thunderstorm winds/flooding"   
## [47] "highway flooding"               "heavy rain/mudslides/flood"    
## [49] "snowmelt flooding"              "beach flood"                   
## [51] "thunderstorm winds/ flood"      "flood & heavy rain"            
## [53] "urban small stream flood"       "urban flood landslide"         
## [55] "urban floods"                   "heavy rain/urban flood"        
## [57] "landslide/urban flood"          "ice jam flood (minor"          
## [59] "coastalflood"                   "erosion/cstl flood"            
## [61] "tidal flooding"                 "street flooding"               
## [63] "flood/strong wind"              "urban/street flooding"         
## [65] "cstl flooding/erosion"
transitdata$EVTYPE[grepl("flood",transitdata$EVTYPE)] <- "flood"

cleandata <- rbind(cleandata, transitdata)

#Reverise the "FLOOD" to "flood" 
cleandata$EVTYPE[grepl("coastal FLOOD",cleandata$EVTYPE)] <- "coastal flood"
cleandata$EVTYPE[grepl("flash FLOOD",cleandata$EVTYPE)] <- "flash flood"
cleandata$EVTYPE[grepl("lakeshore FLOOD",cleandata$EVTYPE)] <- "lakeshore flood"
After standardizing the event types , there are 47 event types, and the event type “debris flow” is not in the dataset.

Check any NA Value

# Checking any NA values
na_value_fatalities <- sum(is.na(cleandata$FATALITIES))
na_value_injuries <- sum(is.na(cleandata$INJURIES))
na_value_propdmg <- sum(is.na(cleandata$PROPDMG))
na_value_propdmgexp <- sum(is.na(cleandata$PROPDMGEXP))
na_value_cropdmg <- sum(is.na(cleandata$CROPDMG))
na_value_cropdmgexp <- sum(is.na(cleandata$CROPDMGEXP))

NA Values for Fatalities : 0
NA Values for Injuries : 0
NA Values for Property Damage : 0
NA Values for Property Damage Exp. : 0
NA Values for Crop Damage : 0
NA Values for Crop Damage Exp. : 0

Damage Value Convertion

  • Convert the Property Damage units in values of ‘B’ for Billions, ‘K’ for thousands, and ‘M’ for millions to numeric equivalent.

  • Combine the Property Damage Amount and Units columns into a new column PROPDMGDOL as the total amount of property damage in US Dollars.

  • Perform the above process for Crop Damage units and amounts.

# Define common convent function
convert_unit_to_number <- function(x){
        x <- as.character(x)
        ifelse (x == "B", as.numeric(1000000000),
        ifelse(x == "M", as.numeric(1000000), 
        ifelse(x == "K", as.numeric(1000), 0)))
}

# Modify the values with upper characters for Properity Damage Unit
cleandata$PROPDMGEXP <- toupper(cleandata$PROPDMGEXP)
cleandata$PROPDMGEXP <- convert_unit_to_number(cleandata$PROPDMGEXP)

#Calculate the Properity Damage in US Dollars.
cleandata$PROPDMGDOL <- as.numeric(cleandata$PROPDMG*cleandata$PROPDMGEXP)

# Perform the same process for Crop Damage Unit and Amount
cleandata$CROPDMGEXP <- toupper(cleandata$CROPDMGEXP)
cleandata$CROPDMGEXP <- convert_unit_to_number(cleandata$CROPDMGEXP)
cleandata$CROPDMGDOL <- as.numeric(cleandata$CROPDMG*cleandata$CROPDMGEXP)
cleandata$TOTALDMGDOL <- cleandata$CROPDMGDOL + cleandata$PROPDMGDOL

Results

Economic Effects of Storm Events

  • In order to determine which event type(EVTYPE) is most harmful the economy, The total damage is sumed by Crop Properity damange and Properity damage into a new data frame, called cleandata. Also, the bar char is drawn with the top 10 events as below.
prop <- aggregate(PROPDMGDOL ~ EVTYPE,cleandata, sum)
crop <- aggregate(CROPDMGDOL ~ EVTYPE,cleandata, sum)
total <- aggregate(TOTALDMGDOL ~ EVTYPE,cleandata, sum)
economic<- join_all(list(prop, crop, total), by = "EVTYPE")
economic <- economic[order(-economic$TOTALDMGDOL),][1:10,]
max_total_damage <- format(economic[which.max(economic$TOTALDMGDOL),"TOTALDMGDOL"],big.mark = ",")
max_event_by_econmic <- economic[which.max(economic$TOTALDMGDOL),"EVTYPE"]
economic<- melt(economic, id=c("EVTYPE"), measure.vars=c("PROPDMGDOL","CROPDMGDOL"))
economic$EVTYPE <- as.factor(economic$EVTYPE)
 ggplot(data=economic, aes(EVTYPE, value, fill =variable)) + geom_bar(stat="identity")+xlab("Storm and Weather Event") + ylab("Total Damage in US Dollars") + ggtitle("Crop and Property Damage by Storm Event")

  • The result is a lttle bit surpurise that the ’r max_event_by_econmic is the most harmful event. It is because it is the side effect produced by other major events such as Storm, and Thunderstorm.
fatalities <- aggregate(FATALITIES ~ EVTYPE,cleandata, sum)
injuries <- aggregate(INJURIES ~ EVTYPE,cleandata, sum)

health <- join_all(list(fatalities, injuries), by = "EVTYPE")
health$TOTAL <- health$FATALITIES + health$INJURIES
health <- health[order(-health$TOTAL),][1:10,]
max_event_by_totalhealth <- health[which.max(health$TOTAL),"EVTYPE"]
max_fatalities <- format(health[grepl(max_event_by_totalhealth,health$EVTYPE),"FATALITIES"],big.mark = ",")
max_injuries <- format(health[grepl(max_event_by_totalhealth,health$EVTYPE),"INJURIES"],big.mark = ",")
health <- melt(health, id=c("EVTYPE"), measure.vars=c("FATALITIES","INJURIES"))
health$EVTYPE <- as.factor(health$EVTYPE)
ggplot(data=health, aes(EVTYPE, value, fill =variable)) + geom_bar(stat="identity")+xlab("Event") + ylab("Total") + ggtitle("Injuries and Fatalities by Event")

Economic Effects of Storm Events

  • In order to determine which event type(EVTYPE) is most harmful the economy, The total damage is sumed by fatalities and injuries into a new data frame, called cleandata. Also, the bar char is drawn with the top 10 events as below.

Conclusion

flood caused the most economic damage, with over 161,029,512,600 dollars in property and crop damage. tornado is the most dangerous having caused 5,661 fatalities and 91,407 injuries since 1996.

On the basis of this report, preventative measures aimed at reducing casualties and damage during tornadoes and hurricanes will have the greatest economic and health impacts.