processing the data
library(tidyverse)
stormDataSubset <- stormData %>% select(EVTYPE, FATALITIES, INJURIES,PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP)
stormDataSubset$EVTYPE <- as.factor(stormDataSubset$EVTYPE)
accumulating the data
totalFatalties <- aggregate(FATALITIES ~ EVTYPE, stormDataSubset, FUN = sum)
totalFatalties <- arrange(totalFatalties, desc(FATALITIES))
totalFataltiesTop10 <- totalFatalties[1:10,]
totalInjuries <- aggregate(INJURIES ~ EVTYPE, stormDataSubset, FUN = sum)
totalInjuries <- arrange(totalInjuries, desc(INJURIES))
totalInjuriesTop10 <- totalInjuries[1:10,]
if (stormDataSubset$PROPDMGEXP == "K") {
stormDataSubset$PROPDMG = stormDataSubset$PROPDMG * 1000
}
## Warning in if (stormDataSubset$PROPDMGEXP == "K") {: the condition has length >
## 1 and only the first element will be used
if (stormDataSubset$PROPDMGEXP == "M"){
stormDataSubset$PROPDMG = stormDataSubset$PROPDMG * 1000000
}
## Warning in if (stormDataSubset$PROPDMGEXP == "M") {: the condition has length >
## 1 and only the first element will be used
if (stormDataSubset$PROPDMGEXP == "B"){
stormDataSubset$PROPDMG = stormDataSubset$PROPDMG * 1000000000
}
## Warning in if (stormDataSubset$PROPDMGEXP == "B") {: the condition has length >
## 1 and only the first element will be used
totalPropertyDMG <- aggregate(PROPDMG ~ EVTYPE, stormDataSubset, FUN = sum)
totalPropertyDMG <- arrange(totalPropertyDMG, desc(PROPDMG))
if (stormDataSubset$CROPDMGEXP == "K") {
stormDataSubset$CROPDMG = stormDataSubset$CROPDMG * 1000
}
## Warning in if (stormDataSubset$CROPDMGEXP == "K") {: the condition has length >
## 1 and only the first element will be used
if (stormDataSubset$CROPDMGEXP == "M"){
stormDataSubset$CROPDMG = stormDataSubset$CROPDMG * 1000000
}
## Warning in if (stormDataSubset$CROPDMGEXP == "M") {: the condition has length >
## 1 and only the first element will be used
if (stormDataSubset$CROPDMGEXP == "B"){
stormDataSubset$CROPDMG = stormDataSubset$CROPDMG * 1000000000
}
## Warning in if (stormDataSubset$CROPDMGEXP == "B") {: the condition has length >
## 1 and only the first element will be used
totalCorpDMG <- aggregate(CROPDMG ~ EVTYPE, stormDataSubset, FUN = sum)
totalCorpDMG <- arrange(totalCorpDMG, desc(CROPDMG))
totalEconomyDMG<- merge(totalPropertyDMG, totalCorpDMG, by = "EVTYPE")
totalEconomyDMG$totalDMG <- totalEconomyDMG$PROPDMG + totalEconomyDMG$CROPDMG
totalEconomyDMG <- arrange(totalEconomyDMG, desc(totalDMG))
totalEconomyDMGTop10 <- totalEconomyDMG[1:10, ]