#Load database repdata_data_StormData1 <- read_csv(“ReproducibleResearch/week2/repdata_data_StormData1.csv”)

#Data processing The database was loaded into R by importing the data into the laboratory environment provided by the course to carry out the activity and processed for analysis.

#Meteorological Data Analysis Analysis of the database of the National Oceanic and Atmospheric Administration of the United States (NOAA)

#Questions to resolve Does the analysis address the question of what types of events are most detrimental to population health?

Does the analysis address the question of what types of events have the greatest economic consequences?

#Note Since a detailed record was not kept before 1996, you will take this date from now on since this year they began to be recorded more precisely.

data <- repdata_data_StormData1 data\(BGN_DATE <- strptime(data\)BGN_DATE, “%m/%d/%Y %H:%M:%S”) data <- subset(data, BGN_DATE > “1995-12-31”)

#Transform the data For this analysis we will only need these variables

data <- subset(data, select = c(EVTYPE, FATALITIES, INJURIES, PROPDMG, PROPDMGEXP, CROPDMG, CROPDMGEXP))

data\(EVTYPE <- toupper(data\)EVTYPE)

#Delete zero data data <- data[data\(FATALITIES !=0 | + data\)INJURIES !=0 | + data\(PROPDMG !=0 | + data\)CROPDMG !=0, ]

#Population health data processing #Here we add fatalities and injuries to identify the first ten

Economic_data <- aggregate(cbind(PROPDMGTOTAL,CROPDMGTOTAL) ~ EVTYPE, data=data, FUN=sum) Economic_data\(ECONOMIC_LOSS <- Economic_data\)PROPDMGTOTAL + Economic_data\(CROPDMGTOTAL Economic_data <- Economic_data[order(Economic_data\)ECONOMIC_LOSS, decreasing = TRUE), ] Top10_events_economy <- Economic_data[1:10,] print(Top10_events_economy)

#Economic consequences Health_data <- aggregate(cbind(FATALITIES, INJURIES) ~ EVTYPE, data = data, FUN=sum) Health_data\(PEOPLE_LOSS <- Health_data\)FATALITIES + Health_data\(INJURIES Health_data <- Health_data[order(Health_data\)PEOPLE_LOSS, decreasing = TRUE), ] Top10_events_people <- Health_data[1:10,] print(Top10_events_people)

EVTYPE FATALITIES INJURIES PEOPLE_LOSS 368 TORNADO 5633 91346 96979 50 EXCESSIVE HEAT 1903 6525 8428 383 TSTM WIND 504 6957 7461 74 FLOOD 470 6789 7259 230 LIGHTNING 816 5230 6046 129 HEAT 937 2100 3037 61 FLASH FLOOD 978 1777 2755 213 ICE STORM 89 1975 2064 326 THUNDERSTORM WIND 133 1488 1621 438 WINTER STORM 206 1321 1527

EVTYPE PROPDMGTOTAL CROPDMGTOTAL ECONOMIC_LOSS 74 FLOOD 144657709807 168037.88 144657877845 200 HURRICANE/TYPHOON 69305840000 4798.48 69305844798 368 TORNADO 56947381216 100018.52 56947481235 314 STORM SURGE 43323536000 5.00 43323536005 61 FLASH FLOOD 16822723978 179200.46 16822903179 112 HAIL 15735267513 579596.28 15735847109 191 HURRICANE 11868319010 5339.31 11868324349 378 TROPICAL STORM 7703890550 5899.12 7703896449 438 WINTER STORM 6688497251 1978.99 6688499230 176 HIGH WIND 5270046475 17283.21 5270063758

#Plots Plotting health loss

library(ggplot2) g <- ggplot(data = Top10_events_people, aes(x = reorder(EVTYPE, PEOPLE_LOSS), y = PEOPLE_LOSS)) g <- g + geom_bar(stat = “identity”, colour = “black”) g <- g + labs(title = “Total people loss in USA by weather events in 1996-2011”) g <- g + theme(plot.title = element_text(hjust = 0.5)) g <- g + labs(y = “Number of fatalities and injuries”, x = “Event Type”) g <- g + coord_flip() print(g)

library(ggplot2) g <- ggplot(data = Top10_events_economy, aes(x = reorder(EVTYPE, ECONOMIC_LOSS), y = ECONOMIC_LOSS)) g <- g + geom_bar(stat = “identity”, colour = “black”) g <- g + labs(title = “Total economic loss in USA by weather events in 1996-2011”) g <- g + theme(plot.title = element_text(hjust = 0.5)) g <- g + labs(y = “Size of property and crop loss”, x = “Event Type”) g <- g + coord_flip() print(g)

#Results Types of events are most harmful to the health of the population Tornado

The events that have the most economic consequences Flood