crashData <- read.csv("New York Crash Data.csv")
crashData
## Rank County Pedestrians.Killed
## 1 1 ALBANY (1) 8
## 2 2 ALLEGANY (3) 0
## 3 3 BRONX (5) 18
## 4 4 BROOME (7) 3
## 5 5 CATTARAUGUS (9) 0
## 6 6 CAYUGA (11) 0
## 7 7 CHAUTAUQUA (13) 1
## 8 8 CHEMUNG (15) 1
## 9 9 CHENANGO (17) 1
## 10 10 CLINTON (19) 0
## 11 11 COLUMBIA (21) 1
## 12 12 CORTLAND (23) 0
## 13 13 DELAWARE (25) 0
## 14 14 DUTCHESS (27) 7
## 15 15 ERIE (29) 5
## 16 16 ESSEX (31) 0
## 17 17 FRANKLIN (33) 0
## 18 18 FULTON (35) 0
## 19 19 GENESEE (37) 1
## 20 20 GREENE (39) 1
## 21 21 HAMILTON (41) 0
## 22 22 HERKIMER (43) 0
## 23 23 JEFFERSON (45) 3
## 24 24 KINGS (47) 38
## 25 25 LEWIS (49) 0
## 26 26 LIVINGSTON (51) 1
## 27 27 MADISON (53) 0
## 28 28 MONROE (55) 13
## 29 29 MONTGOMERY (57) 0
## 30 30 NASSAU (59) 21
## 31 31 NEW YORK (61) 18
## 32 32 NIAGARA (63) 5
## 33 33 ONEIDA (65) 5
## 34 34 ONONDAGA (67) 4
## 35 35 ONTARIO (69) 2
## 36 36 ORANGE (71) 7
## 37 37 ORLEANS (73) 1
## 38 38 OSWEGO (75) 1
## 39 39 OTSEGO (77) 0
## 40 40 PUTNAM (79) 2
## 41 41 QUEENS (81) 30
## 42 42 RENSSELAER (83) 4
## 43 43 RICHMOND (85) 6
## 44 44 ROCKLAND (87) 7
## 45 45 ST. LAWRENCE (89) 2
## 46 46 SARATOGA (91) 6
## 47 47 SCHENECTADY (93) 3
## 48 48 SCHOHARIE (95) 0
## 49 49 SCHUYLER (97) 0
## 50 50 SENECA (99) 0
## 51 51 STEUBEN (101) 1
## 52 52 SUFFOLK (103) 52
## 53 53 SULLIVAN (105) 2
## 54 54 TIOGA (107) 1
## 55 55 TOMPKINS (109) 0
## 56 56 ULSTER (111) 0
## 57 57 WARREN (113) 2
## 58 58 WASHINGTON (115) 2
## 59 59 WAYNE (117) 1
## 60 60 WESTCHESTER (119) 16
## 61 61 WYOMING (121) 0
## 62 62 YATES (123) 0
#CLEANING UP DATA: CREATING VARIABLES TO MAKE DATA EASIER TO WORK WITH, REMOVING NA'S
county <- na.omit(crashData$County)
countCounties <- length(county)
peopleKilled <- na.omit(crashData$Pedestrians.Killed)
totalKilled <- sum(peopleKilled)
cat("This data shows how many pedestrians were killed in each county of New York in 2022. The number of counties in New york is", countCounties, ". The total number of pedestrians killed is", totalKilled, ".\n" )
## This data shows how many pedestrians were killed in each county of New York in 2022. The number of counties in New york is 62 . The total number of pedestrians killed is 303 .
#AVERAGE KILLED PER COUNTY
averageKilled <- mean(peopleKilled)
cat("The average amount of pedestrians killed per county is",averageKilled, ".\n")
## The average amount of pedestrians killed per county is 4.887097 .
#RANGE OF PEDESTRIANS KILLED + ZERO DEATH COUNTIES
minKilled <- min(peopleKilled)
maxKilled <- max(peopleKilled)
cat("The least number of people killed in a county is", minKilled, "While the most killed in a county is", maxKilled)
## The least number of people killed in a county is 0 While the most killed in a county is 52
zeroDeaths <- crashData$County[crashData$Pedestrians.Killed==0]
cat("The counties that had 0 deaths in 2022 are:" , zeroDeaths)
## The counties that had 0 deaths in 2022 are: ALLEGANY (3) CATTARAUGUS (9) CAYUGA (11) CLINTON (19) CORTLAND (23) DELAWARE (25) ESSEX (31) FRANKLIN (33) FULTON (35) HAMILTON (41) HERKIMER (43) LEWIS (49) MADISON (53) MONTGOMERY (57) OTSEGO (77) SCHOHARIE (95) SCHUYLER (97) SENECA (99) TOMPKINS (109) ULSTER (111) WYOMING (121) YATES (123)
# BARPLOT TO VISUALIZE DEATH COUNT
barplot(peopleKilled,
main = "Number of Pedestrians Killed",
xlab = "Counties",
ylab = "number of deaths")
