The missing value was excluded. The population health was assessed by the sum of the number of fatalities and injuries.The type of events with maximum fatalities and injuries was identified. The result were showed using bar chart. ### Results TORNADO is most harmful type of events with respect to population health.
storm_data<- read.csv("/Users/cxdy/Downloads/repdata_data_StormData.csv")
storm_data$sum_fatalities_and_injuries<- storm_data$FATALITIES+storm_data$INJURIES
storm_data$EVTYPE_clean<-toupper(storm_data$EVTYPE)
storm_data$EVTYPE_clean[storm_data$EVTYPE_clean == "?"] <- NA
sum_by_type_fi <- aggregate(sum_fatalities_and_injuries ~ EVTYPE_clean, data = storm_data, FUN = sum)
max_index <- which.max(sum_by_type_fi$sum_fatalities_and_injuries)
max_EVTYPE <- sum_by_type_fi$EVTYPE_clean[max_index]
print(paste(max_EVTYPE,"is most harmful type of events with respect to population health"))
## [1] "TORNADO is most harmful type of events with respect to population health"
barplot(sum_by_type_fi$sum_fatalities_and_injuries, names.arg = sum_by_type_fi$EVTYPE_clean,main = "Event affect fatalities and injuries Analysis",xlab = "Event Type", ylab = "Number of fatalities and injuries")
The missing value was excluded. The economic consequences was assessed by the PROPDMG.PROPDMG was transferred to same unit of measurement according to the PROPDMGEXP. The type of events with maximum economic consequences was identified. The result were showed using bar chart. ### Results FLOOD has the greatest economic consequences.
PROPDMGEXP_clean <- ifelse(storm_data$PROPDMGEXP %in% c("B", "K", "M"), storm_data$PROPDMGEXP, NA)
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
storm_data<-storm_data %>% mutate(PROPDMG_clean = ifelse(
PROPDMGEXP == "B", PROPDMG * 10^9,
ifelse(
PROPDMGEXP == "M", PROPDMG * 10^6,
ifelse(
PROPDMGEXP == "K", PROPDMG * 10^3,
PROPDMG
)
)
)
)
sum_by_type_prodmg <- aggregate(PROPDMG_clean ~ EVTYPE_clean, data = storm_data, FUN = sum)
max_index_PROPDMG <- which.max(sum_by_type_prodmg$PROPDMG_clean)
max_EVTYPE_PROPDMG <- sum_by_type_prodmg$EVTYPE_clean[max_index_PROPDMG]
print(paste(max_EVTYPE_PROPDMG,"has the greatest economic consequences"))
## [1] "FLOOD has the greatest economic consequences"
barplot(sum_by_type_prodmg$PROPDMG_clean, names.arg = sum_by_type_prodmg$EVTYPE_clean, main = "Event Property Damage Analysis",xlab = "Event Type", ylab = "Property Damage")