Finding the main contributor for health and economic consequences among Storms

The following analysis includes:
1.Importing the required data
2.Splitting by the type of Disaster
3.Summing up the health and economic impacts for each Disaster
4.Displaying the results

Data Processing:

Reading the data

library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
raw<-read_csv("repdata_data_StormData.csv.bz2",show_col_types = FALSE)

Subsetting for storm type, fatalities, and injuries

health<-raw[,c("EVTYPE","FATALITIES","INJURIES")]

Splitting by Storm type(“EVTYPE”)

sp_health<-split(health,health$EVTYPE)

Building data frame with Storm type and corresponding sum of Fatalities, and Injuries

spA_health<-data.frame("FATALITIES"=sapply(sp_health,function(s){sum(unlist(s$FATALITIES))}),
                       "INJURIES"=sapply(sp_health,function(s){sum(unlist(s$INJURIES))}))

Subsetting for Storm type, economic damages

econom<-raw[,c("EVTYPE","PROPDMG","PROPDMGEXP","CROPDMG","CROPDMGEXP")]

Converting DMG and DMGEXP into one variable since dmgexp corresponds to the base 10 exponent for the dmg variable

exp_multiplier <- function(exp_char) {
  dplyr::case_when(
    tolower(exp_char) == "k" ~ 1e3,
    tolower(exp_char) == "m" ~ 1e6,
    tolower(exp_char) == "b" ~ 1e9,
    .default = 1
  )
}

comb_econom <- econom[, c("EVTYPE", "PROPDMG", "CROPDMG")]
comb_econom$PROPDMG <- econom$PROPDMG * exp_multiplier(econom$PROPDMGEXP)
comb_econom$CROPDMG <- econom$CROPDMG * exp_multiplier(econom$CROPDMGEXP)

sp_econom <- split(comb_econom, comb_econom$EVTYPE)
spA_econom <- data.frame(
  "CROPDMG" = sapply(sp_econom, function(x) sum(x$CROPDMG)),
  "PROPDMG" = sapply(sp_econom, function(x) sum(x$PROPDMG)),
  "TOTAL"   = sapply(sp_econom, function(x) sum(x$CROPDMG) + sum(x$PROPDMG))
)

Results:

#Maximum Fatalities
par(mar = c(5, 10.5, 4.1, 2.1)) 
spA_health<-spA_health[order(-spA_health$FATALITIES),]
barplot(spA_health$FATALITIES[1:10],main = "Top 10. Fatalities per EVTYPE",
        names.arg = rownames(spA_health)[1:10],las=2,horiz = TRUE,col="blue")

spA_health[which.max(spA_health$FATALITIES),]
##         FATALITIES INJURIES
## TORNADO       5633    91346
sort(spA_health$FATALITIES,decreasing=TRUE)[1:10]
##  [1] 5633 1903  978  937  816  504  470  368  248  224
#Maximum Injuries
spA_health<-spA_health[order(-spA_health$INJURIES),]
barplot(spA_health$INJURIES[1:10],main="Top 10. Injuries per EVTYPE",
        names.arg = rownames(spA_health)[1:10],las=2,horiz = TRUE,col="turquoise")

spA_health[which.max(spA_health$INJURIES),]
##         FATALITIES INJURIES
## TORNADO       5633    91346
#Maximum Total Damage
spA_econom<-spA_econom[order(-spA_econom$TOTAL),]
barplot(spA_econom$TOTAL[1:10],main="Top 10. Total Damage per EVTYPE",
        names.arg = rownames(spA_econom)[1:10],las=2,horiz = TRUE,col="#003153")

spA_econom[which.max(spA_econom$TOTAL),]
##          CROPDMG      PROPDMG        TOTAL
## FLOOD 5661968450 144657709807 150319678257

Highest Fatalities in TORNADO
Highest Injuries in TORNADO
Highest Damage in FLOOD