Skip to content

Commit

Permalink
Data cleaning and prep completed.
Browse files Browse the repository at this point in the history
Two working subsets created.

still pending - actual analysis and writing the report.
  • Loading branch information
NickLauerman committed May 20, 2014
1 parent 66db5b2 commit ac0d530
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
24 changes: 20 additions & 4 deletions report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,30 @@ data$cropdmgexp <- sub("\\?", "0", data$cropdmgexp)
data$cropdmgexp <- sub("" , "0", data$cropdmgexp)
# convert to a numeric
data$cropdmgexp <- as.numeric(data$cropdmgexp)
#
# compute total prop and crop damages the total financial loss report for each event
#
temp <- data$propdmg * (10 ^ data$propdmgexp)
data <- cbind(data,
data.frame(propcash = temp))
temp <- data$cropdmg * (10 ^ data$cropdmgexp)
data <- cbind(data,
data.frame(cropcash = temp))
temp <- data$propcash + data$cropcash
data <- cbind(data,
data.frame(totalcash = temp))
rm(temp)
```


```{r building working data, cache=TRUE}
#health.impact <- subset(data,
# ((health >0) & (bgn_date > as.Date("1991-01-01", "%Y-%m-%d"))),
# select=c(bgn_date,evtype,health))
#financial.impact <- subset(work, ((propdmg > 0) | (cropdmg > 0)))
health.impact <- subset(data,
((health >0) & (bgn_date > as.Date("1991-01-01", "%Y-%m-%d"))),
select=c(bgn_date,evtype,health))
financial.impact <- subset(data,
((totalcash > 0) & (bgn_date > as.Date("1991-01-01", "%Y-%m-%d"))),
select = c(bgn_date, evtype, propcash, cropcash, totalcash))
```


Expand Down
84 changes: 84 additions & 0 deletions report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Title
========================================================


Synopsis:

Data Processing

```r
data <- read.csv("data/repdata-data-StormData.csv.bz2",
stringsAsFactors = FALSE)
```


```r
names(data) <- tolower(names(data))
data$bgn_date <- as.Date(data$bgn_date, "%m/%d/%Y")
data$evtype <- as.factor(data$evtype)
data <- cbind(data,
data.frame(health = apply(subset(data, select = c(fatalities,
injuries)),
1,
sum)
)
)

# make propdmgexp usable
data$propdmgexp <- sub("h", "2", data$propdmgexp, ignore.case = TRUE)
data$propdmgexp <- sub("k", "3", data$propdmgexp, ignore.case = TRUE)
data$propdmgexp <- sub("m", "6", data$propdmgexp, ignore.case = TRUE)
data$propdmgexp <- sub("b", "9", data$propdmgexp, ignore.case = TRUE)
# deal with unknown variables.
data$propdmgexp <- sub("-", "0", data$propdmgexp)
data$propdmgexp <- sub("\\?","0",data$propdmgexp)
data$propdmgexp <- sub("\\+", "0", data$propdmgexp)
data$propdmgexp <- sub("","0", data$propdmgexp)
# convert to a numeric
data$propdmgexp <- as.numeric(data$propdmgexp)
#
# make cropdmgexp usable
#
data$cropdmgexp <- sub("h", "2", data$cropdmgexp, ignore.case = TRUE)
data$cropdmgexp <- sub("k", "3", data$cropdmgexp, ignore.case = TRUE)
data$cropdmgexp <- sub("m", "6", data$cropdmgexp, ignore.case = TRUE)
data$cropdmgexp <- sub("b", "9", data$cropdmgexp, ignore.case = TRUE)
# deal with unknown variables.
data$cropdmgexp <- sub("-" , "0", data$cropdmgexp)
data$cropdmgexp <- sub("\\+", "0", data$cropdmgexp)
data$cropdmgexp <- sub("\\?", "0", data$cropdmgexp)
data$cropdmgexp <- sub("" , "0", data$cropdmgexp)
# convert to a numeric
data$cropdmgexp <- as.numeric(data$cropdmgexp)
#
# compute total prop and crop damages the total financial loss report for each event
#

temp <- data$propdmg * (10 ^ data$propdmgexp)
data <- cbind(data,
data.frame(propcash = temp))
temp <- data$cropdmg * (10 ^ data$cropdmgexp)
data <- cbind(data,
data.frame(cropcash = temp))
temp <- data$propcash + data$cropcash
data <- cbind(data,
data.frame(totalcash = temp))
rm(temp)
```




```r
health.impact <- subset(data,
((health >0) & (bgn_date > as.Date("1991-01-01", "%Y-%m-%d"))),
select=c(bgn_date,evtype,health))
financial.impact <- subset(data,
((totalcash > 0) & (bgn_date > as.Date("1991-01-01", "%Y-%m-%d"))),
select = c(bgn_date, evtype, propcash, cropcash, totalcash))
```



Results

0 comments on commit ac0d530

Please sign in to comment.