Total economic damage, which is sum of porperty damage and crop damage, is calculated. Event types are sorted based on economic damage. Top five event types are shown. “Flood” is caused the most economic damage. Total health damage, which is sum of fatalities and injuries, is calculated. Event types are sorted based on health damage. Top five event types are shown. “Tornado” is caused the most health damage.
First step is to load data and select reqired coluns such as event type, fatalities, injuries, property damage, property damage exponent, crop damage, and crop damage exponent.
stormdata <- read.csv(bzfile("repdata%2Fdata%2FStormData.csv.bz2"))
damagedata <- data.frame(event.type=stormdata$EVTYPE,
fatalities=stormdata$FATALITIES, injuries=stormdata$INJURIES,
prop.damage=stormdata$PROPDMG, prop.damage.scale=stormdata$PROPDMGEXP,
crop.damage=stormdata$CROPDMG, crop.damage.scale=stormdata$CROPDMGEXP)
Property damage and crop damage are calculatd by multiplng damages and their respective multipling factors. These factors are calculated from property damage exponent and crop damage exponent.
levels(damagedata$prop.damage.scale)<-c(0,0,0,1,10,10,10,10,10,10,10,10,10,1000000000,100,100,1000,1000000,1000000)
levels(damagedata$crop.damage.scale)<-c(0,0,10,10,1000000000,1000,1000,1000000,1000000)
damagedata$prop <-damagedata$prop.damage * as.numeric(as.character(damagedata$prop.damage.scale))
damagedata$crop <-damagedata$crop.damage * as.numeric(as.character(damagedata$crop.damage.scale))
Total economic damage is calculated by adding property damage and crop damage.
damagedata$economic <- damagedata$prop + damagedata$crop
Total health damage is calculated by adding fatalities nd injuries.
damagedata$health <- damagedata$fatalities + damagedata$injuries
Sum of economic damage for each event type is calculated.
economic.damage <- aggregate(damagedata$economic ~ damagedata$event.type, FUN = sum)
colnames(economic.damage) <- c("event.type", "economic")
Event types are sorted based on economic damage.
sorted.economic.damage <- economic.damage[order(economic.damage$economic, decreasing = TRUE),]
Here are the top five economic damaging event types:
barplot(sorted.economic.damage[1:5,2]/1000000000,
names.arg = sorted.economic.damage[1:5,1],
col = "blue", cex.names = 0.5,
main = "Top five economic damaging event types",
ylab = "economic damage in Billion dollars")
Sum of health damage for each event type is calculated.
health.damage <- aggregate(damagedata$health ~ damagedata$event.type, FUN = sum)
colnames(health.damage) <- c("event.type", "health")
Event types are sorted based on health damage.
sorted.health.damage <- health.damage[order(health.damage$health, decreasing = TRUE),]
Here are the top five health damaging event types:
barplot(sorted.health.damage[1:5,2],
names.arg = sorted.health.damage[1:5,1],
col = "blue", cex.names = 0.5,
main = "Top five health damaging event types",
ylab = "Health damage count")