Pete Castillo
2023-11-27
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Rows: 7728394 Columns: 46
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (17): ID, Source, Description, Street, City, County, State, Zipcode, Co...
## dbl (13): Severity, Start_Lat, Start_Lng, End_Lat, End_Lng, Distance(mi), T...
## lgl (13): Amenity, Bump, Crossing, Give_Way, Junction, No_Exit, Railway, Ro...
## dttm (3): Start_Time, End_Time, Weather_Timestamp
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 582,837
## Columns: 46
## $ ID <chr> "A-261009", "A-261010", "A-261011", "A-261012", …
## $ Source <chr> "Source2", "Source2", "Source2", "Source2", "Sou…
## $ Severity <dbl> 2, 2, 2, 2, 3, 2, 3, 2, 2, 3, 3, 2, 2, 2, 3, 3, …
## $ Start_Time <dttm> 2016-11-30 16:03:54, 2016-11-30 16:32:18, 2016-…
## $ End_Time <dttm> 2016-11-30 17:20:00, 2016-11-30 17:47:02, 2016-…
## $ Start_Lat <dbl> 30.33650, 30.32816, 30.32608, 32.85601, 32.79767…
## $ Start_Lng <dbl> -97.75565, -97.69430, -97.69231, -97.51308, -97.…
## $ End_Lat <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ End_Lng <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ `Distance(mi)` <dbl> 0.01, 0.00, 0.00, 0.01, 0.01, 0.01, 0.01, 0.00, …
## $ Description <chr> "Accident on RM-2222 Northland Dr at Mo Pac Expy…
## $ Street <chr> "Mopac Expy S", "E Saint Johns Ave", "Cameron Rd…
## $ City <chr> "Austin", "Austin", "Austin", "Fort Worth", "For…
## $ County <chr> "Travis", "Travis", "Travis", "Tarrant", "Tarran…
## $ State <chr> "TX", "TX", "TX", "TX", "TX", "TX", "TX", "TX", …
## $ Zipcode <chr> "78731", "78752-2826", "78752", "76135", "76118"…
## $ Country <chr> "US", "US", "US", "US", "US", "US", "US", "US", …
## $ Timezone <chr> "US/Central", "US/Central", "US/Central", "US/Ce…
## $ Airport_Code <chr> "KATT", "KATT", "KATT", "KAWN", "KFWD", "KRBD", …
## $ Weather_Timestamp <dttm> 2016-11-30 15:51:00, 2016-11-30 16:51:00, 2016-…
## $ `Temperature(F)` <dbl> 66.0, 62.1, 62.1, NA, NA, 60.1, 61.0, 61.0, 59.0…
## $ `Wind_Chill(F)` <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ `Humidity(%)` <dbl> 24, 25, 25, NA, NA, 24, 22, 22, 23, 22, 23, 21, …
## $ `Pressure(in)` <dbl> 30.01, 30.03, 30.03, NA, NA, 30.00, 30.01, 30.01…
## $ `Visibility(mi)` <dbl> 10, 10, 10, NA, NA, 10, 10, 10, 10, 10, 10, 10, …
## $ Wind_Direction <chr> "NNW", "North", "North", "North", NA, "Variable"…
## $ `Wind_Speed(mph)` <dbl> 5.8, 4.6, 4.6, NA, NA, 5.8, 4.6, 4.6, 10.4, 4.6,…
## $ `Precipitation(in)` <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ Weather_Condition <chr> "Clear", "Clear", "Clear", NA, NA, "Clear", "Cle…
## $ Amenity <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Bump <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Crossing <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Give_Way <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Junction <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ No_Exit <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Railway <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Roundabout <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Station <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, …
## $ Stop <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Traffic_Calming <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Traffic_Signal <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, F…
## $ Turning_Loop <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
## $ Sunrise_Sunset <chr> "Day", "Day", "Day", "Day", "Day", "Day", "Day",…
## $ Civil_Twilight <chr> "Day", "Day", "Day", "Day", "Day", "Day", "Day",…
## $ Nautical_Twilight <chr> "Day", "Day", "Day", "Day", "Day", "Day", "Day",…
## $ Astronomical_Twilight <chr> "Day", "Day", "Day", "Day", "Day", "Day", "Day",…
A brief look at accident data in Texas.
## [1] "ID" "Source" "Severity"
## [4] "Start_Time" "End_Time" "Start_Lat"
## [7] "Start_Lng" "End_Lat" "End_Lng"
## [10] "Distance(mi)" "Description" "Street"
## [13] "City" "County" "State"
## [16] "Zipcode" "Country" "Timezone"
## [19] "Airport_Code" "Weather_Timestamp" "Temperature(F)"
## [22] "Wind_Chill(F)" "Humidity(%)" "Pressure(in)"
## [25] "Visibility(mi)" "Wind_Direction" "Wind_Speed(mph)"
## [28] "Precipitation(in)" "Weather_Condition" "Amenity"
## [31] "Bump" "Crossing" "Give_Way"
## [34] "Junction" "No_Exit" "Railway"
## [37] "Roundabout" "Station" "Stop"
## [40] "Traffic_Calming" "Traffic_Signal" "Turning_Loop"
## [43] "Sunrise_Sunset" "Civil_Twilight" "Nautical_Twilight"
## [46] "Astronomical_Twilight" "Year"
Start_Time & End_Time
Start_Lat, Start_Lat - Shows longitude and latitude in GPS coordinate of the start point.
Severity - Shows the severity of the accident, a number between 1 and 4, where 1 indicates the least impact on traffic.
## [1] "2016-11-30 16:03:54 UTC"
## # A tibble: 8 × 2
## Year Accidents
## <chr> <int>
## 1 2021 101830
## 2 2022 95509
## 3 2017 85588
## 4 2018 84111
## 5 2019 78718
## 6 2020 73488
## 7 2016 49769
## 8 2023 13824
## # A tibble: 6 × 2
## Year Accidents
## <chr> <int>
## 1 2021 101830
## 2 2022 95509
## 3 2017 85588
## 4 2018 84111
## 5 2019 78718
## 6 2020 73488
Added the values in ‘Accidents’ column for years 2017-2022
Number of rows = number of years in dataset
Divided the sum of the total accidents by the amount of years (rows).
## [1] 86540.67
## # A tibble: 1 × 1
## AverageMonthlyRate
## <dbl>
## 1 7212.
## [1] 7211.722
## [1] 78729.5
## # A tibble: 2 × 2
## Period Accidents
## <chr> <int>
## 1 Holiday Period 119621
## 2 Other Months 463216