Created
August 4, 2016 15:57
-
-
Save ckholmes5/dff0d2d211262723523a09c2e05aeffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clean = select(df, YEAR, STATE, FATALS, A_DIST, A_SPCRA, A_POSBAC) | |
clean$YEAR = as.character(clean$YEAR) | |
#All Fatalities by year | |
total_fatal = summarise(group_by(clean, YEAR), FATALS = sum(FATALS)) | |
#Drunk Driving | |
dd = mutate(clean, A_POSBAC=replace(A_POSBAC, A_POSBAC>1, 0)) | |
dd = mutate(dd, drunk_fatals = FATALS*A_POSBAC) | |
dd_fatal = summarise(group_by(dd, YEAR), FATALS = sum(drunk_fatals)) | |
#Distracted Driving | |
distract = mutate(clean, A_DIST=replace(A_DIST, A_DIST>1, 0)) | |
distract = mutate(distract, distract_fatals = FATALS*A_DIST) | |
distract_fatal = summarise(group_by(distract, YEAR), FATALS = sum(distract_fatals)) | |
#Speeding | |
speeding = mutate(clean, A_SPCRA = replace(A_SPCRA, A_SPCRA > 1, 0)) | |
speeding = mutate(speeding, speeding_fatals = A_SPCRA*FATALS) | |
speeding_fatal = summarise(group_by(speeding, YEAR), FATALS = sum(speeding_fatals)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment