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")

lrData <- read.csv("Left Right Data.csv")
timeOne <- lrData$Time1
timeTwo <- lrData$Time2
leftOrRight <- lrData$Left_or_Right
# TRYING TO SEE HOW MANY RIGHTS VERSUS HOW MANY LEFTS
rightCount <- 0
leftCount <- 0
dataLength <- length(leftOrRight)
for(i in 1:dataLength){
if(leftOrRight[i] == "Right" || leftOrRight[i]== "right" ){
rightCount<- rightCount + 1 }
if(leftOrRight[i]== "Left" || leftOrRight[i]== "left"){
leftCount<- leftCount + 1 }
}
cat("The right count is", rightCount, "\n")
## The right count is 10
cat("The left count is", leftCount, "\n")
## The left count is 14
# AVG TIMES
# adding all the time ones, and all the time twos. I did data length times 2 because total length of this sum is the data length twice
avgTime <- sum(timeOne, timeTwo) / (dataLength*2)
cat("The average time taken to get to a student's seat is" , avgTime , "\n")
## The average time taken to get to a student's seat is 9.546875
# GETTING AVERAGE TIMES PER ROW AND COMPARING THEM
rowOne <- c()
rowTwo <- c()
rowThree <- c()
rowFour <- c()
for (i in 1:dataLength){
if (lrData$Row[i] == 1){
rowOne <- append(rowOne, lrData$Time1[i])
rowOne <- append(rowOne, lrData$Time2[i])
}
if (lrData$Row[i] == 2){
rowTwo <- append(rowTwo, lrData$Time1[i])
rowTwo <- append(rowTwo, lrData$Time2[i])
}
if (lrData$Row[i] == 3){
rowThree <- append(rowThree, lrData$Time1[i])
rowThree <- append(rowThree, lrData$Time2[i])
}
if (lrData$Row[i] == 4){
rowFour <- append(rowFour, lrData$Time1[i])
rowFour <- append(rowFour, lrData$Time2[i])
}
}
avgRowOne <- mean (rowOne)
avgRowTwo <- mean (rowTwo)
avgRowThree <- mean (rowThree)
avgRowFour <- mean (rowFour)
cat("The time average for the first row is", avgRowOne, "\n")
## The time average for the first row is 8.071
cat("The time average for the second row is", avgRowTwo, "\n")
## The time average for the second row is 8.406
cat("The time average for the third row is", avgRowThree, "\n")
## The time average for the third row is 10.02833
cat("The time average for the fourth row is", avgRowFour, "\n")
## The time average for the fourth row is 11.01