Synopsis

In this NOAA Storm Database analysis we explore the severe weather events.Across the United States,showing which types of events as indicated in the EVTYPE color{green} are most harmful with respect to population health. Also Across the United States showing which types of events have the greatest economic consequences represented in color red.

Data Processing

I start by down loading the data from web site , and the unzib the CSV and finaly load the the data to start the analysis. I start then displaying and selecting data to health and economic impact analysis against weather.using the field property damage exponential by desplaying the contenet which is alphabet in PROPDM i start transforming letters in to numbers exponential stored in PROPEXP exaple K= 1000 etc and give value 0 to space or any other sign like + ?, finaly calulate the value of the property damage PROPDMGVAL by multiplying the the value of PROPDM by PROPEXPand storing it in PROPDMGVAL, same calculation was done for the crops. After that i start aggregating the data from the fields FATALITIES by EVTYPE,INJURIES by EVTYPE,PROPDMGVAL by EVTYPE and CROPDMGVAL by EVTYPE and store them in the following fields Fatal,Injury,propdamg,Cropdamg.

Results

Finaly to display the results i get top 10 event with highest fatalities and Injuries and using BarPlot I ploted them in color grenn the injuries and fatalities against wether storms showing the highest injuries and Fatlities against Tornado. Also The same Barplot ploted ther result in red showing property damages and crops damages against wether storms where the highst for Property was th flood and Drought was the highet damages for the crops.

download file from URL

if (!file.exists("C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv.bz2")) {
  download.file("https://d396qusza40orc.cloudfront.net/repdata%2Fdata%2FStormData.csv.bz2", 
"C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv.bz2")
}

unzip file

if(!file.exists("C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv."))
library(R.utils)
bunzip2("C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv.bz2","C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv, remove = FALSE)}

load data into R

storm <- read.csv("C:/Users/Administrator/Desktop/coursera/preassignment/repdata-data-StormData.csv")
head(storm)
##   STATE__           BGN_DATE BGN_TIME TIME_ZONE COUNTY COUNTYNAME STATE
## 1       1  4/18/1950 0:00:00     0130       CST     97     MOBILE    AL
## 2       1  4/18/1950 0:00:00     0145       CST      3    BALDWIN    AL
## 3       1  2/20/1951 0:00:00     1600       CST     57    FAYETTE    AL
## 4       1   6/8/1951 0:00:00     0900       CST     89    MADISON    AL
## 5       1 11/15/1951 0:00:00     1500       CST     43    CULLMAN    AL
## 6       1 11/15/1951 0:00:00     2000       CST     77 LAUDERDALE    AL
##    EVTYPE BGN_RANGE BGN_AZI BGN_LOCATI END_DATE END_TIME COUNTY_END
## 1 TORNADO         0                                               0
## 2 TORNADO         0                                               0
## 3 TORNADO         0                                               0
## 4 TORNADO         0                                               0
## 5 TORNADO         0                                               0
## 6 TORNADO         0                                               0
##   COUNTYENDN END_RANGE END_AZI END_LOCATI LENGTH WIDTH F MAG FATALITIES
## 1         NA         0                      14.0   100 3   0          0
## 2         NA         0                       2.0   150 2   0          0
## 3         NA         0                       0.1   123 2   0          0
## 4         NA         0                       0.0   100 2   0          0
## 5         NA         0                       0.0   150 2   0          0
## 6         NA         0                       1.5   177 2   0          0
##   INJURIES PROPDMG PROPDMGEXP CROPDMG CROPDMGEXP WFO STATEOFFIC ZONENAMES
## 1       15    25.0          K       0                                    
## 2        0     2.5          K       0                                    
## 3        2    25.0          K       0                                    
## 4        2     2.5          K       0                                    
## 5        2     2.5          K       0                                    
## 6        6     2.5          K       0                                    
##   LATITUDE LONGITUDE LATITUDE_E LONGITUDE_ REMARKS REFNUM
## 1     3040      8812       3051       8806              1
## 2     3042      8755          0          0              2
## 3     3340      8742          0          0              3
## 4     3458      8626          0          0              4
## 5     3412      8642          0          0              5
## 6     3450      8748          0          0              6

subset the data to health and economic impact analysis against weather event

mycol <- c("EVTYPE", "FATALITIES", "INJURIES", "PROPDMG", "PROPDMGEXP", "CROPDMG", 
"CROPDMGEXP")
mydata <- storm[mycol]

exploring the property exponent

unique(mydata$PROPDMGEXP)
##  [1] K M   B m + 0 5 6 ? 4 2 3 h 7 H - 1 8
## Levels:  - ? + 0 1 2 3 4 5 6 7 8 B h H K m M

Sorting the property exponent data

mydata$PROPEXP[mydata$PROPDMGEXP == "K"] <- 1000
mydata$PROPEXP[mydata$PROPDMGEXP == "M"] <- 1e+06
mydata$PROPEXP[mydata$PROPDMGEXP == ""] <- 1
mydata$PROPEXP[mydata$PROPDMGEXP == "B"] <- 1e+09
mydata$PROPEXP[mydata$PROPDMGEXP == "m"] <- 1e+06
mydata$PROPEXP[mydata$PROPDMGEXP == "0"] <- 1
mydata$PROPEXP[mydata$PROPDMGEXP == "5"] <- 1e+05
mydata$PROPEXP[mydata$PROPDMGEXP == "6"] <- 1e+06
mydata$PROPEXP[mydata$PROPDMGEXP == "4"] <- 10000
mydata$PROPEXP[mydata$PROPDMGEXP == "2"] <- 100
mydata$PROPEXP[mydata$PROPDMGEXP == "3"] <- 1000
mydata$PROPEXP[mydata$PROPDMGEXP == "h"] <- 100
mydata$PROPEXP[mydata$PROPDMGEXP == "7"] <- 1e+07
mydata$PROPEXP[mydata$PROPDMGEXP == "H"] <- 100
mydata$PROPEXP[mydata$PROPDMGEXP == "1"] <- 10
mydata$PROPEXP[mydata$PROPDMGEXP == "8"] <- 1e+08

give 0 to invalid exponent data, so they not count in

mydata$PROPEXP[mydata$PROPDMGEXP == "+"] <- 0
mydata$PROPEXP[mydata$PROPDMGEXP == "-"] <- 0
mydata$PROPEXP[mydata$PROPDMGEXP == "?"] <- 0

compute the property damage value

mydata$PROPDMGVAL <- mydata$PROPDMG * mydata$PROPEXP

exploring the crop exponent data

unique(mydata$CROPDMGEXP)
## [1]   M K m B ? 0 k 2
## Levels:  ? 0 2 B k K m M

Sorting the property exponent data

mydata$CROPEXP[mydata$CROPDMGEXP == "M"] <- 1e+06
mydata$CROPEXP[mydata$CROPDMGEXP == "K"] <- 1000
mydata$CROPEXP[mydata$CROPDMGEXP == "m"] <- 1e+06
mydata$CROPEXP[mydata$CROPDMGEXP == "B"] <- 1e+09
mydata$CROPEXP[mydata$CROPDMGEXP == "0"] <- 1
mydata$CROPEXP[mydata$CROPDMGEXP == "k"] <- 1000
mydata$CROPEXP[mydata$CROPDMGEXP == "2"] <- 100
mydata$CROPEXP[mydata$CROPDMGEXP == ""] <- 1

give 0 to invalid exponent data, so they not count in

mydata$CROPEXP[mydata$CROPDMGEXP == "?"] <- 0

compute the crop damage value

mydata$CROPDMGVAL <- mydata$CROPDMG * mydata$CROPEXP

aggregate the data by event

fatal <- aggregate(FATALITIES ~ EVTYPE, data = mydata, FUN = sum)
injury <- aggregate(INJURIES ~ EVTYPE, data = mydata, FUN = sum)
propdmg <- aggregate(PROPDMGVAL ~ EVTYPE, data = mydata, FUN = sum)
cropdmg <- aggregate(CROPDMGVAL ~ EVTYPE, data = mydata, FUN = sum)

get top10 event with highest fatalities

fatal10 <- fatal[order(-fatal$FATALITIES), ][1:10, ]

get top10 event with highest injuries

injury10 <- injury[order(-injury$INJURIES), ][1:10, ]
par(mfrow = c(1, 2), mar = c(12, 4, 3, 2), mgp = c(3, 1, 0), cex = 0.8)
barplot(fatal10$FATALITIES, las = 3, names.arg = fatal10$EVTYPE, main = "Weather Events With The Top 10 Highest Fatalities", ylab = "number of fatalities", col = "green")
barplot(injury10$INJURIES, las = 3, names.arg = injury10$EVTYPE, main = "Weather Events With the Top 10 Highest Injuries", ylab = "number of injuries", col = "green")

get top 10 events with highest property damage

propdmg10 <- propdmg[order(-propdmg$PROPDMGVAL), ][1:10, ]

get top 10 events with highest crop damage

cropdmg10 <- cropdmg[order(-cropdmg$CROPDMGVAL), ][1:10, ]
par(mfrow = c(1, 2), mar = c(12, 4, 3, 2), mgp = c(3, 1, 0), cex = 0.8)
barplot(propdmg10$PROPDMGVAL/(10^9), las = 3, names.arg = propdmg10$EVTYPE,main = "Top 10 Events with Greatest Property Damages", ylab = "Cost of damages ($ billions)",col = "red")
barplot(cropdmg10$CROPDMGVAL/(10^9), las = 3, names.arg = cropdmg10$EVTYPE, 
main = "Top 10 Events With Greatest Crop Damages", ylab = "Cost of damages ($ billions)", 
col = "red")