Synopsis: The data were processed to analyze the types of events that are most harmful with respect to population health, and that have the greatest economic consequences.

Data Processing

setwd("~/Desktop/coursera/Reproducible Research/Course Project 2")
aa<- read.csv("repdata_data_StormData.csv")

Result: 1. To find out which types of events are most harmful with respect to population health:

bb<- sapply(split(aa$FATALITIES, aa$EVTYPE), sum)
cc<- names(bb)
dd<- as.data.frame(bb)
colnames(dd)<- "FATALITIES"
dd$EVTYPES<- cc
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
dd<- arrange(dd, FATALITIES)
ee<- sapply(split(aa$INJURIES, aa$EVTYPE), sum)
ff<- names(ee)
gg<- as.data.frame(ee)
colnames(gg)<- "INJURIES"
gg$EVTYPES <- ff
gg<- arrange(gg, INJURIES)

The events that have the most fatality and injury, respectively:

tail(dd, 1)
##         FATALITIES EVTYPES
## TORNADO       5633 TORNADO
tail(gg, 1)
##         INJURIES EVTYPES
## TORNADO    91346 TORNADO

To show a relative figure respect to population death:

rr<- tail(dd, 1)
tt<- tail(gg, 1)
yy<- cbind(rr, tt)
yy[, 2]<- NULL
library(tidyr)
yy<- yy %>% gather(types, numbers, "FATALITIES", "INJURIES")
barplot(yy$numbers, names.arg = c("FATALITIES", "INJURIES"), main = "Population loss caused by tornado")

Result: 2.To find out which types of events have the greatest economic consequences:

qq<- aa %>% filter(PROPDMGEXP == "K" | PROPDMGEXP == "M" | PROPDMGEXP == "B")
for(i in nrow(qq)){
  if(qq$PROPDMGEXP == "K"){
    qq$PROPDMG <- qq$PROPDMG/1000
    qq$PROPDMGEXP <- "M"
  } else if (aa$PROPDMGEXP == "B"){
    qq$PROPDMG <- qq$PROPDMG*1000
    qq$PROPDMGEXP <- "M"
  }
}
## Warning in if (qq$PROPDMGEXP == "K") {: the condition has length > 1 and only
## the first element will be used
ww<- with(qq, tapply(PROPDMG, EVTYPE, sum))
ww<- as.data.frame(ww)
colnames(ww)<- "Loss(M)"
ww<-arrange(ww, ww$`Loss(M)`)
tail(ww, 1)
##          Loss(M)
## TORNADO 3211.948

The type of event that has the greatest econimic consequences:

tail(ww, 1)
##          Loss(M)
## TORNADO 3211.948