Across the United States, which types of events (as indicated in the EVTYPE variable) are most harmful with respect to population health?
Across the United States, which types of events have the greatest economic consequences?
You can download the file from the course web site here
Data Documentation:
1. National
Weather Service
2. National
Climatic Data Center Storm Events
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## Warning: package 'ggplot2' was built under R version 4.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
setwd("C:/Users/gpond/Desktop/Research Project 2")
if(!exists("storm.data")) {
d <- read.csv(bzfile("repdata_data_StormData.csv.bz2"),header = TRUE)
}
d <- d %>% select(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
d <- d %>% mutate(EVTYPE = toupper(EVTYPE)) %>% mutate(EVENT = if_else(grepl("WIND", EVTYPE), 'WIND',
if_else(grepl("HEAT", EVTYPE), 'HEAT',
if_else(grepl("FLOOD", EVTYPE), 'FLOOD',
if_else(grepl("HAIL", EVTYPE), 'HAIL',
if_else(grepl("STORM", EVTYPE), 'STORM',
if_else(grepl("SNOW", EVTYPE), 'SNOW',
if_else(grepl("TORNADO", EVTYPE), 'TORNADO',
if_else(grepl("WINTER", EVTYPE), 'WINTER',
if_else(grepl("RAIN", EVTYPE), 'RAIN','OTHER'))))))))))
health_event <- d %>% group_by(EVENT) %>% summarize(FATALITIES = sum(FATALITIES),
INJURIES = sum(INJURIES))
d$PROPDMGEXP <- as.character(d$PROPDMGEXP)
d$PROPDMGEXP[is.na(d$PROPDMGEXP)] <- 0
d$PROPDMGEXP[!grepl("K|M|B", d$PROPDMGEXP, ignore.case = TRUE)] <- 0
d$PROPDMGEXP[grep("K", d$PROPDMGEXP, ignore.case = TRUE)] <- "3"
d$PROPDMGEXP[grep("M", d$PROPDMGEXP, ignore.case = TRUE)] <- "6"
d$PROPDMGEXP[grep("B", d$PROPDMGEXP, ignore.case = TRUE)] <- "9"
d$PROPDMGEXP <- as.numeric(as.character(d$PROPDMGEXP))
d$property.damage <- d$PROPDMG * 10^d$PROPDMGEXP
d$CROPDMGEXP <- as.character(d$CROPDMGEXP)
d$CROPDMGEXP[is.na(d$CROPDMGEXP)] <- 0 # NA's considered as dollars
d$CROPDMGEXP[!grepl("K|M|B", d$CROPDMGEXP, ignore.case = TRUE)] <- 0
d$CROPDMGEXP[grep("K", d$CROPDMGEXP, ignore.case = TRUE)] <- "3"
d$CROPDMGEXP[grep("M", d$CROPDMGEXP, ignore.case = TRUE)] <- "6"
d$CROPDMGEXP[grep("B", d$CROPDMGEXP, ignore.case = TRUE)] <- "9"
d$CROPDMGEXP <- as.numeric(as.character(d$CROPDMGEXP))
d$crop.damage <- d$CROPDMG * 10^d$CROPDMGEXP
sort(table(d$property.damage), decreasing = TRUE)[1:10]
##
## 0 5000 10000 1000 2000 25000 50000 3000 20000 15000
## 663123 31731 21787 17544 17186 17104 13596 10364 9179 8617
sort(table(d$crop.damage), decreasing = TRUE)[1:10]
##
## 0 5000 10000 50000 1e+05 1000 2000 25000 20000 5e+05
## 880198 4097 2349 1984 1233 956 951 830 758 721
econ_event <- d %>% group_by(EVENT) %>% summarize(Crop = sum(CROPDMGEXP),
Property = sum(PROPDMGEXP))
The Greatest Health Impact comes from Tornado.
The Greatest Economic Impact comes from Wind.