According to the U.S. National Oceanic and Atmospheric Administration’s (NOAA) storm database for the last six decades US economy has lost 477 billion USD through severe weather events, i.e. the annual GDP of a country like Sweden. More than 15 thousand persons have lost their lives and some 141 thousands have been wounded. Most of the economic consequences of the natural disasters are property-related damages. However agricultural losses are either non-neglegable. Tornadoes, excessive heat, lightning and to the lesser extent floods are mostly responsable for fatalities and injuries. Whereas the primary causes of property damages are floods, hurricanes and tornadoes. Drought is obviously the main reason of the crop damage. Taking health and property damages together floods, tornadoes and hurricanes have had the most pronouncing devastating effect. Some care schould be taken, though, with respect to the conclusions presented above. More we drill down to the history of observations less data are reliable.More profound data cleaning work has to be undertaken in order to get more precise results.

  options(warn=-1)
  library(ggplot2)
  # the library contains functions allowing to combine several ggplots
  library(gridExtra) 
## Loading required package: grid

Data processing

Brief descriptions of the data cleaning stage. Only columns nedeed for the analysis have been selected. Property and crop damage data are converted into numeric format by means of an auxillary multiplier conversion table. Any number in “exp” columns is treated as a power of 10 (like thousands,millions etc.). Any non-numeric or unrecognizable symbol is omitted (property/crop damage is taken as it is). Then the pdf description file is parsed so as to get standardized types of weather events. Finally storm data is aggregated using these newly created standardized types. For this purposes a function was written (shown below). It takes the types as they were recorded historically and translates them into standardized ones. Certainly, it’s far from perfect and the correspondence between recorded and standardized types is often very approximate.

1.Processing NOAA Storm Database

# auxillary dataframe necessary for conversion property and crop losses into numeric monetary units
correspondUnit<-data.frame(c("H","K","M","B"),c(10^2,10^3,10^6,10^9))
names(correspondUnit)<-c("MAG","VALUE")
correspondUnit$MAG<-as.character(correspondUnit$MAG)
#reading data file (after prelimenary analysis only 7 columns selected)
data <- read.csv("repdata-data-StormData.csv.bz2",nrow=10)
names(data)
##  [1] "STATE__"    "BGN_DATE"   "BGN_TIME"   "TIME_ZONE"  "COUNTY"    
##  [6] "COUNTYNAME" "STATE"      "EVTYPE"     "BGN_RANGE"  "BGN_AZI"   
## [11] "BGN_LOCATI" "END_DATE"   "END_TIME"   "COUNTY_END" "COUNTYENDN"
## [16] "END_RANGE"  "END_AZI"    "END_LOCATI" "LENGTH"     "WIDTH"     
## [21] "F"          "MAG"        "FATALITIES" "INJURIES"   "PROPDMG"   
## [26] "PROPDMGEXP" "CROPDMG"    "CROPDMGEXP" "WFO"        "STATEOFFIC"
## [31] "ZONENAMES"  "LATITUDE"   "LONGITUDE"  "LATITUDE_E" "LONGITUDE_"
## [36] "REMARKS"    "REFNUM"
storm_data<-read.csv("repdata-data-StormData.csv.bz2",header = TRUE,colClasses=c(rep("NULL",7),"character",rep("NULL",14),"numeric","numeric","numeric","character","numeric","character",rep("NULL",9)))
#converting property and crop damages into USD
property<-mapply(function(x,y){ifelse(grepl("[^0-9A-Za-z]",y)|y=="",x,ifelse(grepl("^[0-9]",y),x*(10^as.numeric(y)),x*correspondUnit[which(correspondUnit$MAG==toupper(y)),2]))},storm_data$PROPDMG,storm_data$PROPDMGEXP)
crop<-mapply(function(x,y){ifelse(grepl("[^0-9A-Za-z]",y)|y=="",x,ifelse(grepl("^[0-9]",y),x*(10^as.numeric(y)),x*correspondUnit[which(correspondUnit$MAG==toupper(y)),2]))},storm_data$CROPDMG,storm_data$CROPDMGEXP)
storm_data<-data.frame(storm_data,property,crop)
names(storm_data)[names(storm_data)=="property"]<-"PROPERTY"
names(storm_data)[names(storm_data)=="crop"]<-"CROP"
#some preparation of EVTYPE column for the next step
storm_data$EVTYPE<-as.character(storm_data$EVTYPE )
storm_data$EVTYPE<-sapply(storm_data$EVTYPE,function(x){toupper(x)})

2.Processing Storm Data Documentation file

#reading and parsing pdf file and creating an character array of statndardized types of weather events
system("pdftotext 'repdata-peer2_doc-pd01016005curr.pdf' storm.txt -layout -f 2 -l 4")
storm_text<-readLines("storm.txt")
storm_text<-data.frame(storm_text)
names(storm_text)<-c("TYPE")
storm_text$TYPE<-as.character(storm_text$TYPE)
storm_text$TYPE<-sapply(storm_text$TYPE,function(x){gsub("^\\s+","",x)})
storm_text<-subset(storm_text,grepl("\\(M)?",storm_text$TYPE)|grepl("\\(Z)?",storm_text$TYPE)|grepl("\\(C)?",storm_text$TYPE),select=c(TYPE))
storm_text$TYPE<-sapply(storm_text$TYPE, function (x) { substr(x,(regexpr("[A-Z]",x))[1],(regexpr("\\(",x))[1]-1)})
storm_text$TYPE<-sapply(storm_text$TYPE,function(x){gsub(" $","",x)})

3.Aggregating storm data across all types of events

#aggregation of the row data by the event types and excluding all-zero observations 
ag_sd<-aggregate(cbind(FATALITIES,INJURIES,PROPERTY,CROP)~EVTYPE,data=storm_data,sum)
ag_sd<-subset(ag_sd,ag_sd$FATALITIES!=0|ag_sd$INJURIES!=0|ag_sd$PROPERTY!=0|ag_sd$CROP!=0)
#function "compare" makes the hidden work to create a new array with standardized event types
source("compare.R")
dd<-compare(ag_sd,storm_text)
ag_sd<-data.frame(ag_sd,dd$NEW)
names(ag_sd)[6]<-"EVTYPENEW"
#aggregation of data the by the standardized event types
ag_sd<-aggregate(cbind(FATALITIES,INJURIES,PROPERTY,CROP)~EVTYPENEW,data=ag_sd,sum)
ag_sd<-data.frame(ag_sd,(ag_sd$FATALITIES+ag_sd$INJURIES),(ag_sd$PROPERTY+ag_sd$CROP))
names(ag_sd)[c(6,7)]<-c("HEALTH","ECONOMIC")
ag_sd$EVTYPENEW<-as.character(ag_sd$EVTYPENEW)
ag_sd
##                   EVTYPENEW FATALITIES INJURIES     PROPERTY        CROP
## 1     Astronomical Low Tide          0        0       320000           0
## 2                 Avalanche        225      170      3721800           0
## 3                  Blizzard        101      805    659813950   112060000
## 4             Coastal Flood          6        7    413482060       56000
## 5           Cold/Wind Chill         66       48     56554000   101142500
## 6                 Dense Fog         81     1077     22829500           0
## 7               Dense Smoke          0        0       100000           0
## 8                   Drought          2        4   1046106000 13972571780
## 9                Dust Devil          2       43       719130           0
## 10               Dust Storm         22      440      5619000     3600000
## 11           Excessive Heat       1920     6525      7753700   492402000
## 12  Extreme Cold/Wind Chill        496      427     79395400  1335623000
## 13              Flash Flood       1018     1785  17414731089  1437163150
## 14                    Flood        530     6889 150423633386 10950975050
## 15             Freezing Fog         11       38     13504500           0
## 16             Frost/Freeze          8       35     19553200  1997061000
## 17             Funnel Cloud          0        3       194600           0
## 18                     Hail         20     1466  16021881013  3111633873
## 19                     Heat       1129     2544     12457050   407061500
## 20               Heavy Rain        103      306   3238944190   806505800
## 21               Heavy Snow        150     1122    982307750   134683100
## 22                High Surf        158      246    101475000           0
## 23                High Wind        293     1507   6003453043   686301900
## 24        Hurricane/Typhoon        135     1333  85356410010  5516117800
## 25                Ice Storm        103     2369   3959592360  5022114300
## 26         Lake-Effect Snow          0        0     40182000           0
## 27          Lakeshore Flood          0        0      7570000           0
## 28                Lightning        817     5232    930542430    12092090
## 29              Marine Hail          0        0         4000           0
## 30         Marine High Wind         49       59  47967591510      855000
## 31       Marine Strong Wind         15       22       438330           0
## 32 Marine Thunderstorm Wind         10       26       436400       50000
## 33                    Other         93       86    328520600   163061400
## 34              Rip Current        577      529       163000           0
## 35                   Seiche          0        0       980000           0
## 36                    Sleet          2        0      2000000           0
## 37               Storm Tide          0        0      9425150           0
## 38              Strong Wind        139      395    191658740    70813500
## 39        Thunderstorm Wind        731     9464  11149296450  1207144288
## 40                  Tornado       5658    91364  58552152426   417461520
## 41      Tropical Depression          0        0      1737000           0
## 42           Tropical Storm         66      383   7714390550   694896000
## 43                  Tsunami         34      131    144062000       20000
## 44             Volcanic Ash          0        0       500000           0
## 45               Waterspout          6       72     60730200           0
## 46                 Wildfire         90     1608   8501628500   403281630
## 47             Winter Storm        217     1353   6748997251    32444000
## 48           Winter Weather         62      615     27310500    15000000
##    HEALTH     ECONOMIC
## 1       0       320000
## 2     395      3721800
## 3     906    771873950
## 4      13    413538060
## 5     114    157696500
## 6    1158     22829500
## 7       0       100000
## 8       6  15018677780
## 9      45       719130
## 10    462      9219000
## 11   8445    500155700
## 12    923   1415018400
## 13   2803  18851894239
## 14   7419 161374608436
## 15     49     13504500
## 16     43   2016614200
## 17      3       194600
## 18   1486  19133514886
## 19   3673    419518550
## 20    409   4045449990
## 21   1272   1116990850
## 22    404    101475000
## 23   1800   6689754943
## 24   1468  90872527810
## 25   2472   8981706660
## 26      0     40182000
## 27      0      7570000
## 28   6049    942634520
## 29      0         4000
## 30    108  47968446510
## 31     37       438330
## 32     36       486400
## 33    179    491582000
## 34   1106       163000
## 35      0       980000
## 36      2      2000000
## 37      0      9425150
## 38    534    262472240
## 39  10195  12356440738
## 40  97022  58969613946
## 41      0      1737000
## 42    449   8409286550
## 43    165    144082000
## 44      0       500000
## 45     78     60730200
## 46   1698   8904910130
## 47   1570   6781441251
## 48    677     42310500

Results

1.Across the United States, which types of events are most harmful with respect to population health?

ag_sd<-ag_sd[order(-ag_sd$FATALITIES),]
health_chart1<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,FATALITIES), y=FATALITIES)) +geom_bar(stat='identity',fill="#4A4A4A",position = 'dodge') +coord_flip()+ylab("Persons killed")+xlab("Types of events")+ggtitle("TOP FIVE DEADLIEST WEATHER EVENTS")
ag_sd<-ag_sd[order(-ag_sd$INJURIES),]
health_chart2<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,INJURIES), y=INJURIES)) +geom_bar(stat='identity',fill="#4A4A4A",position = 'dodge') +coord_flip()+ylab("Persons injured")+xlab("Types of events")+ggtitle("TOP FIVE WEATHER EVENTS CAUSING MOST INJURIES")
ag_sd<-ag_sd[order(-ag_sd$HEALTH),]
health_chart3<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,HEALTH), y=HEALTH)) +geom_bar(stat='identity',fill="#4A4A4A",position = 'dodge') +coord_flip()+ylab("Persons killed or injuried")+xlab("Types of events")+ggtitle("TOP FIVE MOST HARMFUL WEATHER EVENTS (FATALITIES AND INJURIES COMBINED)")
health_chart<- arrangeGrob(health_chart1, health_chart2, health_chart3, ncol=2,main = textGrob("\n1.WEATHER EVENTS WITH MOST SEVERE HEALTH IMPACT",gp = gpar(fontsize=25)))
health_chart

Tornadoes, floods and heat have lethal effect. These events alongside with thunderstorm wind are also primary causes of injuries.

2.Across the United States, which types of events have the greatest economic consequences?

ag_sd<-ag_sd[order(-ag_sd$PROPERTY),]
econ_chart1<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,PROPERTY), y=PROPERTY/10^9)) +geom_bar(stat='identity',fill="#4A4A4A") +coord_flip()+ylab("Billion USD")+xlab("Types of events")+ggtitle("TOP FIVE COSTLIEST WEATHER EVENTS (PROPERTY DAMAGE)")
ag_sd<-ag_sd[order(-ag_sd$CROP),]
econ_chart2<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,CROP), y=CROP/10^9)) +geom_bar(stat='identity',fill="#4A4A4A") +coord_flip()+ylab("Billion USD")+xlab("Types of events")+ggtitle("TOP FIVE COSTLIEST WEATHER EVENTS(AGRICULTIRUAL DAMAGE)")
ag_sd<-ag_sd[order(-ag_sd$ECONOMIC),]
econ_chart3<-ggplot(head(ag_sd,5), aes(x=reorder(EVTYPENEW,ECONOMIC), y=ECONOMIC/10^9)) +geom_bar(stat='identity',fill="#4A4A4A") +coord_flip()+ylab("Billion USD")+xlab("Types of events")+ggtitle("TOP FIVE COSTLIEST WEATHER EVENTS(PROPERTY AND AGRICULTURE COMBINED)")
econ_chart<- arrangeGrob(econ_chart1, econ_chart2, econ_chart3, ncol=2,main = textGrob("\n2.WEATHER EVENTS WITH MOST SEVERE ECONOMIC IMPACT",gp = gpar(fontsize=25)))
econ_chart                                                                                                                                                

Floods, tornadoes and hurricanes produce the most severe property damages. Draught and floods are main causes of the crop losses.

3.Across the United States, which types of events produce most devastating effect on economy and population together?

ag_sd<-ag_sd[order(ag_sd$EVTYPENEW),]
mat<-data.matrix(ag_sd[c(6,7)],)
rownames(mat)<-c(ag_sd$EVTYPE)
my_palette <- colorRampPalette(c("#F4A460", "#8B3626"))(n = 50)
hm <- heatmap(mat, Rowv=NA, Colv=NA, col = my_palette, scale="column", cexCol=1.2, main="What types of weather events we have  suffered of most?")                                                                                                                                             

Tornadoes are most devastating if we combine health and economic damages.

Function Compare.R

compare <- function(ar1,ar2 ) {

OLD<-ar1\(EVTYPE NEW<-rep("NA",nrow(ar1)) ar3<-data.frame(OLD,NEW) ar3\)NEW<-as.character(ar3\(NEW) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*URBAN.*SMALL*",x),"FLOOD",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*HURRICANE.*|.*TYPHOON.*",x),"HURRICANE/TYPHOON",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("^AVAL",x),"AVALANCHE",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("^HYP",x),"HEAT",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("WINTR",x),gsub("WINTR*","WINTER WEATHER",x),x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*FIRE.*",x),"WILDFIRE",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("^IC.*ROAD.*",x),"FROST/FREEZE",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("HVY",x),gsub("HVY","HEAVY",x),x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("*.BURST|GUST.*",x),"THUNDERSTORM WINDS",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*FROST.*|.*FREEZE.*",x),"FROST/FREEZE",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*EXTREME|EXTENDED.*COLD|CHILL.*",x),"EXTREME COLD/WIND CHILL",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl(".*GLAZE.*",x),"ICE STORM",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("SHOWER",x),gsub("SHOWER","RAIN",x),x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("RAINFALL",x),"HEAVY RAIN",x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("PRECIPITATION",x),gsub("PRECIPITATION","RAIN",x),x)}) ar1\)EVTYPE<-sapply(ar1\(EVTYPE,function(x){ifelse(grepl("LAKE EFFECT",x),gsub("LAKE EFFECT","LAKE-EFFECT",x),x)}) ar1\)EVTYPE<-sapply(ar1$EVTYPE,function(x){ifelse(grepl(“LAKE FLOOD”,x),gsub(“LAKE FLOOD”,“LAKESHORE FLOOD”,x),x)})

for (i in 1:nrow(ar2)) {

for (j in 1:nrow(ar1)) {

 if (ar3$NEW[j]=="NA")
 {
   if (grepl(paste0("^",ar2$TYPE[i]),ar1$EVTYPE[j],ignore.case=TRUE))
   {
     
      ar3$NEW[j]<-ar2$TYPE[i]
   }
 }
 

} } for (i in 1:nrow(ar2)) { for (j in 1:nrow(ar1)) {

   if (ar3$NEW[j]=="NA")
   {
     if (grepl(ar2$TYPE[i],ar1$EVTYPE[j],ignore.case=TRUE))
     {
       ar3$NEW[j]<-ar2$TYPE[i] 
     }
   
 } 

} } ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.FREEZING.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Freezing Fog”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*HEAVY SEAS.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Marine High Wind",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.HIGH SEAS.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Marine High Wind”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*HIGH WATER.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Marine High Wind",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.ROUGH SEAS.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Marine High Wind”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*PRECIP.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Heavy Rain",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.EROSION.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Coastal Flood”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*DUST.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Dust Storm",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.FOG.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Dense Fog”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl("^COLD",ar3\)OLD[i]),ar3\(NEW[i]<-"Cold/Wind Chill",ar3\)NEW[i])})
ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.THU.|.TU.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Thunderstorm Wind”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*TSTM.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Thunderstorm Wind",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“[^HEAVY]?.SNOW“,ar3\(OLD[i]),ar3\)NEW[i]<-”Heavy Snow“,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*RAIN.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Heavy Rain",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==”NA“&grepl(”.STORM.“,ar3\(OLD[i]),ar3\)NEW[i]<-”Marine High Wind“,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*WIND.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Strong Wind",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==”NA“&grepl(”.ICE.“,ar3\(OLD[i]),ar3\)NEW[i]<-”Ice Storm“,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*RISING WATER*",ar3\)OLD[i]),ar3\(NEW[i]<-"Flood",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==”NA“&grepl(”.TORN.“,ar3\(OLD[i]),ar3\)NEW[i]<-”Tornado“,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*SURF.*",ar3\)OLD[i]),ar3\(NEW[i]<-"High Surf",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==”NA“&grepl(”.LIG.ING.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Lightning”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*TIDE.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Storm Tide",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.WAVE.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Tsunami”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*COLD.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Cold/Wind Chill",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.COOL.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Cold/Wind Chill”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*MIX.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Heavy Rain",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.SURGE.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Marine High Wind”,ar3\(NEW[i])}) ar3\)NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\(NEW[i]=="NA"&grepl(".*SWELL.*",ar3\)OLD[i]),ar3\(NEW[i]<-"Marine Strong Wind",ar3\)NEW[i])}) ar3\(NEW<-sapply(1:nrow(ar3),function(i){ifelse(ar3\)NEW[i]==“NA”&grepl(“.FLD.”,ar3\(OLD[i]),ar3\)NEW[i]<-“Flood”,ar3\(NEW[i])}) ar3\)NEW<-sapply(ar3$NEW,function(x){ifelse(x==“NA”,x<-“Other”,x)}) return (ar3) }