EV CRIS

Desc Stat

library(dplyr)
library(tidyr)
library(DT)
library(fst)
library(summarytools)
setwd("D:/Data_Archive/Crash Data/TX/2025Analysis/Data/2017_2024/SubsetData")
library(fst)
dat= read.fst("CrUnPPr_2017_2024_LimWithNarr2.fst")
names(dat)
##  [1] "Crash_ID"                   "Crash_Date"                
##  [3] "Crash_Time"                 "Crash_Speed_Limit"         
##  [5] "Wthr_Cond_ID"               "Light_Cond_ID"             
##  [7] "Entr_Road_ID"               "Road_Type_ID"              
##  [9] "Road_Algn_ID"               "Surf_Cond_ID"              
## [11] "Traffic_Cntl_ID"            "Investigat_Notify_Time"    
## [13] "Investigat_Arrv_Time"       "Harm_Evnt_ID"              
## [15] "Intrsct_Relat_ID"           "FHE_Collsn_ID"             
## [17] "Obj_Struck_ID"              "Othr_Factr_ID"             
## [19] "Road_Part_Adj_ID"           "Road_Cls_ID"               
## [21] "Road_Relat_ID"              "Cnty_ID"                   
## [23] "City_ID"                    "Latitude"                  
## [25] "Longitude"                  "Onsys_Fl"                  
## [27] "Rural_Fl"                   "Crash_Sev_ID"              
## [29] "Pop_Group_ID"               "Day_of_Week"               
## [31] "Rural_Urban_Type_ID"        "Func_Sys_ID"               
## [33] "Adt_Curnt_Amt"              "Adt_Curnt_Year"            
## [35] "Year"                       "Investigator_Narrative"    
## [37] "Yr_Un"                      "Unit_ID"                   
## [39] "UnitNbr_Un"                 "Unit_Desc_ID"              
## [41] "Veh_Lic_Plate_Nbr"          "VIN"                       
## [43] "Veh_Mod_Year"               "Veh_Color_ID"              
## [45] "Veh_Make_ID"                "Veh_Mod_ID"                
## [47] "Veh_Body_Styl_ID"           "Emer_Respndr_Fl"           
## [49] "Veh_Damage_Description1_Id" "Veh_Damage_Severity1_Id"   
## [51] "Veh_Cmv_Fl"                 "Contrib_Factr_1_ID"        
## [53] "Contrib_Factr_2_ID"         "Pedestrian_Action_ID"      
## [55] "Pedalcyclist_Action_ID"     "PBCAT_Pedestrian_ID"       
## [57] "PBCAT_Pedalcyclist_ID"      "E_Scooter_ID"              
## [59] "Autonomous_Unit_ID"         "Crash_ID_Pr"               
## [61] "Yr_Pr"                      "UnitNbr_Pr"                
## [63] "Prsn_Nbr"                   "Person_ID"                 
## [65] "Prsn_Type_ID"               "Prsn_Occpnt_Pos_ID"        
## [67] "Prsn_Injry_Sev_ID"          "Prsn_Age"                  
## [69] "Prsn_Ethnicity_ID"          "Prsn_Gndr_ID"              
## [71] "Prsn_Ejct_ID"               "Prsn_Rest_ID"              
## [73] "Prsn_Airbag_ID"             "Prsn_Helmet_ID"            
## [75] "Drvr_Lic_Type_ID"           "Drvr_Lic_State_ID"         
## [77] "Drvr_Lic_Number"            "Drvr_Lic_Cls_ID"           
## [79] "Drvr_DOB"                   "Drvr_State_ID"             
## [81] "Drvr_Zip"
dat1a= dat[, c(1, 36, 38, 62, 22:25, 12, 13, 2, 3, 35, 37, 
               61, 63, 60, 4:11, 14:21, 28:32, 43:48, 52, 
               53, 65, 67:75, 58)]
names(dat1a)
##  [1] "Crash_ID"               "Investigator_Narrative" "Unit_ID"               
##  [4] "UnitNbr_Pr"             "Cnty_ID"                "City_ID"               
##  [7] "Latitude"               "Longitude"              "Investigat_Notify_Time"
## [10] "Investigat_Arrv_Time"   "Crash_Date"             "Crash_Time"            
## [13] "Year"                   "Yr_Un"                  "Yr_Pr"                 
## [16] "Prsn_Nbr"               "Crash_ID_Pr"            "Crash_Speed_Limit"     
## [19] "Wthr_Cond_ID"           "Light_Cond_ID"          "Entr_Road_ID"          
## [22] "Road_Type_ID"           "Road_Algn_ID"           "Surf_Cond_ID"          
## [25] "Traffic_Cntl_ID"        "Harm_Evnt_ID"           "Intrsct_Relat_ID"      
## [28] "FHE_Collsn_ID"          "Obj_Struck_ID"          "Othr_Factr_ID"         
## [31] "Road_Part_Adj_ID"       "Road_Cls_ID"            "Road_Relat_ID"         
## [34] "Crash_Sev_ID"           "Pop_Group_ID"           "Day_of_Week"           
## [37] "Rural_Urban_Type_ID"    "Func_Sys_ID"            "Veh_Mod_Year"          
## [40] "Veh_Color_ID"           "Veh_Make_ID"            "Veh_Mod_ID"            
## [43] "Veh_Body_Styl_ID"       "Emer_Respndr_Fl"        "Contrib_Factr_1_ID"    
## [46] "Contrib_Factr_2_ID"     "Prsn_Type_ID"           "Prsn_Injry_Sev_ID"     
## [49] "Prsn_Age"               "Prsn_Ethnicity_ID"      "Prsn_Gndr_ID"          
## [52] "Prsn_Ejct_ID"           "Prsn_Rest_ID"           "Prsn_Airbag_ID"        
## [55] "Prsn_Helmet_ID"         "Drvr_Lic_Type_ID"       "E_Scooter_ID"
head(dat1a[, -c(2)])
##   Crash_ID    Unit_ID UnitNbr_Pr Cnty_ID City_ID Latitude  Longitude
## 1 14570071 14570071_1          1 El Paso El Paso 31.78471 -106.51844
## 2 14881309 14881309_1          1 El Paso Socorro 31.65162 -106.26752
## 3 14881309 14881309_2          2 El Paso Socorro 31.65162 -106.26752
## 4 14963691 14963691_1          1  Harris Houston 29.63043  -95.17126
## 5 14963691 14963691_2          2  Harris Houston 29.63043  -95.17126
## 6 14963691 14963691_3          3  Harris Houston 29.63043  -95.17126
##   Investigat_Notify_Time Investigat_Arrv_Time Crash_Date Crash_Time Year Yr_Un
## 1               11:02 PM             11:02 PM 08/01/2017   11:00 PM 2017  2017
## 2               06:50 PM             07:00 PM 02/17/2017   07:00 PM 2017  2017
## 3               06:50 PM             07:00 PM 02/17/2017   07:00 PM 2017  2017
## 4               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
## 5               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
## 6               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
##   Yr_Pr Prsn_Nbr Crash_ID_Pr Crash_Speed_Limit Wthr_Cond_ID Light_Cond_ID
## 1  2017        1    14570071                65        Clear Dark, Lighted
## 2  2017        1    14881309                15        Clear          Dusk
## 3  2017        1    14881309                15        Clear          Dusk
## 4  2017        1    14963691                50        Clear Dark, Lighted
## 5  2017        1    14963691                50        Clear Dark, Lighted
## 6  2017        1    14963691                50        Clear Dark, Lighted
##                   Entr_Road_ID               Road_Type_ID    Road_Algn_ID
## 1               Not Applicable 4 Or More Lanes, Undivided    Curve, Level
## 2 Other (Explain In Narrative)              2 Lane, 2 Way Straight, Level
## 3 Other (Explain In Narrative)              2 Lane, 2 Way Straight, Level
## 4          Four Entering Roads                       <NA> Straight, Level
## 5          Four Entering Roads                       <NA> Straight, Level
## 6          Four Entering Roads                       <NA> Straight, Level
##   Surf_Cond_ID       Traffic_Cntl_ID               Harm_Evnt_ID
## 1          Dry Center Stripe/Divider               Fixed Object
## 2          Dry          Marked Lanes Motor Vehicle In Transport
## 3          Dry          Marked Lanes Motor Vehicle In Transport
## 4          Dry          Signal Light Motor Vehicle In Transport
## 5          Dry          Signal Light Motor Vehicle In Transport
## 6          Dry          Signal Light Motor Vehicle In Transport
##   Intrsct_Relat_ID                                 FHE_Collsn_ID
## 1 Non Intersection            One Motor Vehicle - Going Straight
## 2 Non Intersection Opposite Direction - One Straight-One Backing
## 3 Non Intersection Opposite Direction - One Straight-One Backing
## 4     Intersection                   Angle - Both Going Straight
## 5     Intersection                   Angle - Both Going Straight
## 6     Intersection                   Angle - Both Going Straight
##                            Obj_Struck_ID
## 1 Hit Median Barrier (Concrete Or Cable)
## 2                         Not Applicable
## 3                         Not Applicable
## 4                         Not Applicable
## 5                         Not Applicable
## 6                         Not Applicable
##                                                                                                                        Othr_Factr_ID
## 1 Swerved Or Veered-Reason Not Specified                                                                                            
## 2 Not Applicable                                                                                                                    
## 3 Not Applicable                                                                                                                    
## 4 Not Applicable                                                                                                                    
## 5 Not Applicable                                                                                                                    
## 6 Not Applicable                                                                                                                    
##        Road_Part_Adj_ID         Road_Cls_ID Road_Relat_ID       Crash_Sev_ID
## 1      Main/Proper Lane          Interstate        Median Non-Incapacitating
## 2      Main/Proper Lane      Farm To Market    On Roadway        Not Injured
## 3      Main/Proper Lane      Farm To Market    On Roadway        Not Injured
## 4 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
## 5 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
## 6 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
##           Pop_Group_ID Day_of_Week  Rural_Urban_Type_ID      Func_Sys_ID
## 1 250,000 Pop And Over         TUE Urbanized (200,000+) Rural Interstate
## 2  25,000 - 49,999 Pop         FRI Urbanized (200,000+)             <NA>
## 3  25,000 - 49,999 Pop         FRI Urbanized (200,000+)             <NA>
## 4 250,000 Pop And Over         SAT                 <NA>             <NA>
## 5 250,000 Pop And Over         SAT                 <NA>             <NA>
## 6 250,000 Pop And Over         SAT                 <NA>             <NA>
##   Veh_Mod_Year Veh_Color_ID Veh_Make_ID Veh_Mod_ID      Veh_Body_Styl_ID
## 1         2009        Black        Ford      Focus Passenger Car, 2-Door
## 2         2015        Black   Chevrolet  Silverado                Pickup
## 3         2013         Blue     Hyundai    Genesis Passenger Car, 2-Door
## 4         2001         Gray   Chevrolet      Tahoe Sport Utility Vehicle
## 5         2013       Silver     Hyundai     Tucson Sport Utility Vehicle
## 6         2010        White      Toyota    Corolla Passenger Car, 4-Door
##   Emer_Respndr_Fl           Contrib_Factr_1_ID Contrib_Factr_2_ID Prsn_Type_ID
## 1               N                 Unsafe Speed  Had Been Drinking       Driver
## 2               N        Backed Without Safety               <NA>       Driver
## 3               N                         None               <NA>       Driver
## 4               N Disregard Stop And Go Signal               <NA>       Driver
## 5               N                         None               <NA>       Driver
## 6               N                         None               <NA>       Driver
##           Prsn_Injry_Sev_ID Prsn_Age Prsn_Ethnicity_ID Prsn_Gndr_ID
## 1 Non-Incapacitating Injury       21             White         Male
## 2               Not Injured       55          Hispanic         Male
## 3               Not Injured       22          Hispanic         Male
## 4           Possible Injury       65             Black         Male
## 5               Not Injured       28             White         Male
## 6               Not Injured       36          Hispanic         Male
##   Prsn_Ejct_ID        Prsn_Rest_ID  Prsn_Airbag_ID Prsn_Helmet_ID
## 1           No Shoulder & Lap Belt Deployed, Front Not Applicable
## 2           No             Unknown         Unknown Not Applicable
## 3           No Shoulder & Lap Belt    Not Deployed Not Applicable
## 4           No Shoulder & Lap Belt    Not Deployed Not Applicable
## 5           No Shoulder & Lap Belt  Deployed, Side Not Applicable
## 6           No Shoulder & Lap Belt    Not Deployed Not Applicable
##   Drvr_Lic_Type_ID                     E_Scooter_ID
## 1   Driver License Data Not Available At Data Entry
## 2       Unlicensed Data Not Available At Data Entry
## 3   Driver License Data Not Available At Data Entry
## 4   Driver License Data Not Available At Data Entry
## 5   Driver License Data Not Available At Data Entry
## 6       Unlicensed Data Not Available At Data Entry
table(dat1a$Contrib_Factr_1_ID)
## 
##                                            Animal On Road - Domestic 
##                                                                24989 
##                                                Animal On Road - Wild 
##                                                                54420 
##                                                Backed Without Safety 
##                                                               200207 
##                                       Cell/Mobile Device Use - Other 
##                                                                 4765 
##                                     Cell/Mobile Device Use - Talking 
##                                                                 1293 
##                                     Cell/Mobile Device Use - Texting 
##                                                                 2703 
##                                     Cell/Mobile Device Use - Unknown 
##                                                                 2604 
##                                             Changed Lane When Unsafe 
##                                                               325329 
##                                             Disabled In Traffic Lane 
##                                                                10941 
##                                         Disregard Stop And Go Signal 
##                                                               147892 
##                                         Disregard Stop Sign Or Light 
##                                                               100523 
##                                 Disregard Turn Marks At Intersection 
##                                                                19250 
##                               Disregard Warning Sign At Construction 
##                                                                 1811 
##                                               Distraction In Vehicle 
##                                                                50155 
##                                                   Driver Inattention 
##                                                               474046 
##                                           Drove On Improved Shoulder 
##                                                                 1091 
##                                             Drove Without Headlights 
##                                                                 2865 
##                                              Failed To Control Speed 
##                                                              1027703 
##                                       Failed To Drive In Single Lane 
##                                                               276272 
##                                       Failed To Give Half Of Roadway 
##                                                                11011 
##                                          Failed To Heed Warning Sign 
##                                                                 5135 
##                                        Failed To Pass To Left Safely 
##                                                                29913 
##                                       Failed To Pass To Right Safely 
##                                                                12827 
##                                Failed To Signal Or Gave Wrong Signal 
##                                                                 2589 
## Failed To Slow Or Move Over For Vehicles Displaying Emergency Lights 
##                                                                  894 
##                                       Failed To Stop At Proper Place 
##                                                                18390 
##                                        Failed To Stop For School Bus 
##                                                                  266 
##                                             Failed To Stop For Train 
##                                                                  924 
##                     Failed To Yield Right Of Way - Emergency Vehicle 
##                                                                 3201 
##                     Failed To Yield Right Of Way - Open Intersection 
##                                                                54092 
##                         Failed To Yield Right Of Way - Private Drive 
##                                                               150094 
##                             Failed To Yield Right Of Way - Stop Sign 
##                                                               219666 
##                         Failed To Yield Right Of Way - To Pedestrian 
##                                                                10686 
##                           Failed To Yield Right Of Way - Turn On Red 
##                                                                17702 
##                          Failed To Yield Right Of Way - Turning Left 
##                                                               249472 
##                            Failed To Yield Right Of Way - Yield Sign 
##                                                                24220 
##                                                   Fatigued Or Asleep 
##                                                                40808 
##                                                Faulty Evasive Action 
##                                                                97070 
##                                                      Fire In Vehicle 
##                                                                 3093 
##                                            Fleeing Or Evading Police 
##                                                                15280 
##                                                 Followed Too Closely 
##                                                               144838 
##                                                    Had Been Drinking 
##                                                                30999 
##                            Handicapped Driver (Explain In Narrative) 
##                                                                 1282 
##                                           Ill (Explain In Narrative) 
##                                                                20835 
##                           Impaired Visibility (Explain In Narrative) 
##                                                                13224 
##                                  Improper Start From Parked Position 
##                                                                16623 
##                                                     Load Not Secured 
##                                                                12578 
##                                                                 None 
##                                                              4812626 
##                                        Opened Door Into Traffic Lane 
##                                                                 1526 
##                                         Other (Explain In Narrative) 
##                                                               363191 
##                                            Oversized Vehicle Or Load 
##                                                                 5162 
##                             Overtake And Pass Insufficient Clearance 
##                                                                 7785 
##                                      Parked And Failed To Set Brakes 
##                                                                 3317 
##                                               Parked In Traffic Lane 
##                                                                 7612 
##                                                Parked Without Lights 
##                                                                  505 
##                                            Passed In No Passing Lane 
##                                                                 8140 
##                                             Passed On Right Shoulder 
##                                                                 5534 
##                   Pedestrian Failed To Yield Right Of Way To Vehicle 
##                                                                20567 
##                                                            Road Rage 
##                                                                 9474 
##                                               Speeding - (Overlimit) 
##                                                                 8208 
##                             Taking Medication (Explain In Narrative) 
##                                                                  948 
##                               Turned Improperly - Cut Corner On Left 
##                                                                17948 
##                                       Turned Improperly - Wide Right 
##                                                                29188 
##                                       Turned Improperly - Wrong Lane 
##                                                                46793 
##                                                   Turned When Unsafe 
##                                                                79337 
##                                            Under Influence - Alcohol 
##                                                                78725 
##                                               Under Influence - Drug 
##                                                                 9642 
##                                                         Unsafe Speed 
##                                                               158770 
##                                Wrong Side - Approach Or Intersection 
##                                                                 2968 
##                                             Wrong Side - Not Passing 
##                                                                11317 
##                                             Wrong Way - One Way Road 
##                                                                 7338
dat2= read.csv("VEH_MMY_ADS.csv")
head(dat2)
##   Veh_Make_ID Veh_Mod_ID Veh_Mod_Year             VehMMY n_crashes IsElectric
## 1      Nissan     Altima         2015 Nissan_Altima_2015     28240      FALSE
## 2        Ford       F150         2013     Ford_F150_2013     25440      FALSE
## 3        Ford       F150         2014     Ford_F150_2014     22524      FALSE
## 4        Ford       F150         2018     Ford_F150_2018     22032      FALSE
## 5        Ford       F150         2016     Ford_F150_2016     20417      FALSE
## 6        Ford       F150         2015     Ford_F150_2015     19587      FALSE
##   IsHybrid HasAutomaticBrakingSystem HasAutomaticEmergencyBrakingSystem
## 1    FALSE                      TRUE                              FALSE
## 2    FALSE                     FALSE                              FALSE
## 3    FALSE                     FALSE                              FALSE
## 4    FALSE                      TRUE                              FALSE
## 5    FALSE                      TRUE                              FALSE
## 6    FALSE                     FALSE                              FALSE
dat1a$VehMMY=paste0(dat1a$Veh_Make_ID, "_", dat1a$Veh_Mod_ID, 
                    "_",dat1a$Veh_Mod_Year)
dat1b= left_join(dat1a, dat2[, c(4:9)])
dim(dat1a)
## [1] 10001061       58
dim(dat1b)
## [1] 10001061       63
head(dat1b)
##   Crash_ID
## 1 14570071
## 2 14881309
## 3 14881309
## 4 14963691
## 5 14963691
## 6 14963691
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Investigator_Narrative
## 1         I-10 west at mile marker 20 is a four lane public interstate. Lanes are separated by white colored dashes on roadway, all lanes travel in the west direction only.  Wi-01 (Alejandro Barraza 915-626-8399) stated he was traveling west on I-10 behind unit-01. Wi-01 stated as they approached I-10 west at mile marker 20, unit-01 for an unknown reason veered from the number one lane onto the left shoulder colliding into a cement barricade. Unit-01 attempted flee the scene of the accident and continued west on I-10 until the vehicle became disabled and came to a stop on the right shoulder of I-10 west.   Driver of unit-01 was believed to be under the influence of alcohol and or a controlled substance, drug, dangerous drug Case # 15-213199. The driver of unit-01 was transported to Las Palmas Medical center by Fire Rescue 4 to be medically treated. The driver of unit-01 was released to medical staff pending blood test results.
## 2 THE 1200 BLOCK OF HORIZON BLVD IS A TWO WAY, FOUR LANE ROADWAY WITH LANES THAT TRAVEL NORTH AND SOUTH.  UNIT-2 WAS TRAVELING NORTH ONTHE 1200 BLOCK OF  HORIZON BLVD IN THE OUTERLANE.  UNIT-1 WAS FACING SOUTH ON THE 1200 BLOCK OF HORIZON BLVD ATTEMPTING TO MAKE A U-TURN TO TRAVEL NORTH ON HORIZON BLVD.  DRIVER OF UNIT-1 WAS UNABLE TO MAKE A FULL U-TURN TO TRAVEL NORTH.  DRIVER OF UNIT-2 WAS STOPPED BEHIND UNIT-1  WAITING ON UNIT-1 TO CORRECT WHEN DRIVER OF UNIT-1 CONDUCTED AN UNSAFE BACKING AND COLLIDED WITH THE FRONT OF UNIT-2 CAUSING DAMAGE.   UNIT-1 FLED THE SCENE OF THE ACCIDENT AND WAS FOLLOWED BY UNIT-2 TO GATHER INFORMATION OF THE DRIVER AND VEHICLE TO FILE AN ACCIDENT REPORT.  DRIVER OF UNIT-1 FINALLY STOPPED AND ONLY PROVIDED INSURANCE INFORMATION AND FLED AGAIN WITHOUT INTENT TO RETURN.  WARRANT WAS SIGNED AND FILLED AT SOCORRO POLICE HEADQUARTERS FOR DRIVER OF UNIT-1 FOR ACCIDENT INVOLVING DAMAGE TO VEHICLE >=$200.
## 3 THE 1200 BLOCK OF HORIZON BLVD IS A TWO WAY, FOUR LANE ROADWAY WITH LANES THAT TRAVEL NORTH AND SOUTH.  UNIT-2 WAS TRAVELING NORTH ONTHE 1200 BLOCK OF  HORIZON BLVD IN THE OUTERLANE.  UNIT-1 WAS FACING SOUTH ON THE 1200 BLOCK OF HORIZON BLVD ATTEMPTING TO MAKE A U-TURN TO TRAVEL NORTH ON HORIZON BLVD.  DRIVER OF UNIT-1 WAS UNABLE TO MAKE A FULL U-TURN TO TRAVEL NORTH.  DRIVER OF UNIT-2 WAS STOPPED BEHIND UNIT-1  WAITING ON UNIT-1 TO CORRECT WHEN DRIVER OF UNIT-1 CONDUCTED AN UNSAFE BACKING AND COLLIDED WITH THE FRONT OF UNIT-2 CAUSING DAMAGE.   UNIT-1 FLED THE SCENE OF THE ACCIDENT AND WAS FOLLOWED BY UNIT-2 TO GATHER INFORMATION OF THE DRIVER AND VEHICLE TO FILE AN ACCIDENT REPORT.  DRIVER OF UNIT-1 FINALLY STOPPED AND ONLY PROVIDED INSURANCE INFORMATION AND FLED AGAIN WITHOUT INTENT TO RETURN.  WARRANT WAS SIGNED AND FILLED AT SOCORRO POLICE HEADQUARTERS FOR DRIVER OF UNIT-1 FOR ACCIDENT INVOLVING DAMAGE TO VEHICLE >=$200.
## 4                                                   A witnessed observed Unit 1 traveling in the middle lane, NB along 5200 Sam Houston Parkway (NB Feeder Road Beltway 8 Highway), and disregarded a red light and crashing into Unit 2 traveling in the middle WB along 1700 Genoa Red Bluff Rd.After the initial crash, Unit 2 spun out causing a secondary crash into Unit 3 traveling in the outside lane WB along 1700 Genoa Red Bluff Rd. POI #1 is approximately 20’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 30’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).POI #2 is approximately 10’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 40’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).  See Pasadena PD Case#16-5336 in reference to the possible contributing factors for this case being Unit 1 driving under the influence.  Crash Witness Statement attached.
## 5                                                   A witnessed observed Unit 1 traveling in the middle lane, NB along 5200 Sam Houston Parkway (NB Feeder Road Beltway 8 Highway), and disregarded a red light and crashing into Unit 2 traveling in the middle WB along 1700 Genoa Red Bluff Rd.After the initial crash, Unit 2 spun out causing a secondary crash into Unit 3 traveling in the outside lane WB along 1700 Genoa Red Bluff Rd. POI #1 is approximately 20’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 30’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).POI #2 is approximately 10’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 40’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).  See Pasadena PD Case#16-5336 in reference to the possible contributing factors for this case being Unit 1 driving under the influence.  Crash Witness Statement attached.
## 6                                                   A witnessed observed Unit 1 traveling in the middle lane, NB along 5200 Sam Houston Parkway (NB Feeder Road Beltway 8 Highway), and disregarded a red light and crashing into Unit 2 traveling in the middle WB along 1700 Genoa Red Bluff Rd.After the initial crash, Unit 2 spun out causing a secondary crash into Unit 3 traveling in the outside lane WB along 1700 Genoa Red Bluff Rd. POI #1 is approximately 20’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 30’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).POI #2 is approximately 10’ S of the NCL of 1700 Genoa Red Bluff Rd and approximately 40’ W of the ECL of 5200 Sam Houston Parkway (NB Feeder Road – Beltway 8 Highway).  See Pasadena PD Case#16-5336 in reference to the possible contributing factors for this case being Unit 1 driving under the influence.  Crash Witness Statement attached.
##      Unit_ID UnitNbr_Pr Cnty_ID City_ID Latitude  Longitude
## 1 14570071_1          1 El Paso El Paso 31.78471 -106.51844
## 2 14881309_1          1 El Paso Socorro 31.65162 -106.26752
## 3 14881309_2          2 El Paso Socorro 31.65162 -106.26752
## 4 14963691_1          1  Harris Houston 29.63043  -95.17126
## 5 14963691_2          2  Harris Houston 29.63043  -95.17126
## 6 14963691_3          3  Harris Houston 29.63043  -95.17126
##   Investigat_Notify_Time Investigat_Arrv_Time Crash_Date Crash_Time Year Yr_Un
## 1               11:02 PM             11:02 PM 08/01/2017   11:00 PM 2017  2017
## 2               06:50 PM             07:00 PM 02/17/2017   07:00 PM 2017  2017
## 3               06:50 PM             07:00 PM 02/17/2017   07:00 PM 2017  2017
## 4               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
## 5               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
## 6               05:56 AM             05:56 AM 07/15/2017   05:56 AM 2017  2017
##   Yr_Pr Prsn_Nbr Crash_ID_Pr Crash_Speed_Limit Wthr_Cond_ID Light_Cond_ID
## 1  2017        1    14570071                65        Clear Dark, Lighted
## 2  2017        1    14881309                15        Clear          Dusk
## 3  2017        1    14881309                15        Clear          Dusk
## 4  2017        1    14963691                50        Clear Dark, Lighted
## 5  2017        1    14963691                50        Clear Dark, Lighted
## 6  2017        1    14963691                50        Clear Dark, Lighted
##                   Entr_Road_ID               Road_Type_ID    Road_Algn_ID
## 1               Not Applicable 4 Or More Lanes, Undivided    Curve, Level
## 2 Other (Explain In Narrative)              2 Lane, 2 Way Straight, Level
## 3 Other (Explain In Narrative)              2 Lane, 2 Way Straight, Level
## 4          Four Entering Roads                       <NA> Straight, Level
## 5          Four Entering Roads                       <NA> Straight, Level
## 6          Four Entering Roads                       <NA> Straight, Level
##   Surf_Cond_ID       Traffic_Cntl_ID               Harm_Evnt_ID
## 1          Dry Center Stripe/Divider               Fixed Object
## 2          Dry          Marked Lanes Motor Vehicle In Transport
## 3          Dry          Marked Lanes Motor Vehicle In Transport
## 4          Dry          Signal Light Motor Vehicle In Transport
## 5          Dry          Signal Light Motor Vehicle In Transport
## 6          Dry          Signal Light Motor Vehicle In Transport
##   Intrsct_Relat_ID                                 FHE_Collsn_ID
## 1 Non Intersection            One Motor Vehicle - Going Straight
## 2 Non Intersection Opposite Direction - One Straight-One Backing
## 3 Non Intersection Opposite Direction - One Straight-One Backing
## 4     Intersection                   Angle - Both Going Straight
## 5     Intersection                   Angle - Both Going Straight
## 6     Intersection                   Angle - Both Going Straight
##                            Obj_Struck_ID
## 1 Hit Median Barrier (Concrete Or Cable)
## 2                         Not Applicable
## 3                         Not Applicable
## 4                         Not Applicable
## 5                         Not Applicable
## 6                         Not Applicable
##                                                                                                                        Othr_Factr_ID
## 1 Swerved Or Veered-Reason Not Specified                                                                                            
## 2 Not Applicable                                                                                                                    
## 3 Not Applicable                                                                                                                    
## 4 Not Applicable                                                                                                                    
## 5 Not Applicable                                                                                                                    
## 6 Not Applicable                                                                                                                    
##        Road_Part_Adj_ID         Road_Cls_ID Road_Relat_ID       Crash_Sev_ID
## 1      Main/Proper Lane          Interstate        Median Non-Incapacitating
## 2      Main/Proper Lane      Farm To Market    On Roadway        Not Injured
## 3      Main/Proper Lane      Farm To Market    On Roadway        Not Injured
## 4 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
## 5 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
## 6 Service/Frontage Road Us & State Highways    On Roadway    Possible Injury
##           Pop_Group_ID Day_of_Week  Rural_Urban_Type_ID      Func_Sys_ID
## 1 250,000 Pop And Over         TUE Urbanized (200,000+) Rural Interstate
## 2  25,000 - 49,999 Pop         FRI Urbanized (200,000+)             <NA>
## 3  25,000 - 49,999 Pop         FRI Urbanized (200,000+)             <NA>
## 4 250,000 Pop And Over         SAT                 <NA>             <NA>
## 5 250,000 Pop And Over         SAT                 <NA>             <NA>
## 6 250,000 Pop And Over         SAT                 <NA>             <NA>
##   Veh_Mod_Year Veh_Color_ID Veh_Make_ID Veh_Mod_ID      Veh_Body_Styl_ID
## 1         2009        Black        Ford      Focus Passenger Car, 2-Door
## 2         2015        Black   Chevrolet  Silverado                Pickup
## 3         2013         Blue     Hyundai    Genesis Passenger Car, 2-Door
## 4         2001         Gray   Chevrolet      Tahoe Sport Utility Vehicle
## 5         2013       Silver     Hyundai     Tucson Sport Utility Vehicle
## 6         2010        White      Toyota    Corolla Passenger Car, 4-Door
##   Emer_Respndr_Fl           Contrib_Factr_1_ID Contrib_Factr_2_ID Prsn_Type_ID
## 1               N                 Unsafe Speed  Had Been Drinking       Driver
## 2               N        Backed Without Safety               <NA>       Driver
## 3               N                         None               <NA>       Driver
## 4               N Disregard Stop And Go Signal               <NA>       Driver
## 5               N                         None               <NA>       Driver
## 6               N                         None               <NA>       Driver
##           Prsn_Injry_Sev_ID Prsn_Age Prsn_Ethnicity_ID Prsn_Gndr_ID
## 1 Non-Incapacitating Injury       21             White         Male
## 2               Not Injured       55          Hispanic         Male
## 3               Not Injured       22          Hispanic         Male
## 4           Possible Injury       65             Black         Male
## 5               Not Injured       28             White         Male
## 6               Not Injured       36          Hispanic         Male
##   Prsn_Ejct_ID        Prsn_Rest_ID  Prsn_Airbag_ID Prsn_Helmet_ID
## 1           No Shoulder & Lap Belt Deployed, Front Not Applicable
## 2           No             Unknown         Unknown Not Applicable
## 3           No Shoulder & Lap Belt    Not Deployed Not Applicable
## 4           No Shoulder & Lap Belt    Not Deployed Not Applicable
## 5           No Shoulder & Lap Belt  Deployed, Side Not Applicable
## 6           No Shoulder & Lap Belt    Not Deployed Not Applicable
##   Drvr_Lic_Type_ID                     E_Scooter_ID                   VehMMY
## 1   Driver License Data Not Available At Data Entry          Ford_Focus_2009
## 2       Unlicensed Data Not Available At Data Entry Chevrolet_Silverado_2015
## 3   Driver License Data Not Available At Data Entry     Hyundai_Genesis_2013
## 4   Driver License Data Not Available At Data Entry     Chevrolet_Tahoe_2001
## 5   Driver License Data Not Available At Data Entry      Hyundai_Tucson_2013
## 6       Unlicensed Data Not Available At Data Entry      Toyota_Corolla_2010
##   n_crashes IsElectric IsHybrid HasAutomaticBrakingSystem
## 1      3892      FALSE    FALSE                     FALSE
## 2     16872      FALSE    FALSE                     FALSE
## 3      1369      FALSE    FALSE                     FALSE
## 4      5759      FALSE    FALSE                     FALSE
## 5      1519      FALSE    FALSE                     FALSE
## 6     13352      FALSE    FALSE                     FALSE
##   HasAutomaticEmergencyBrakingSystem
## 1                              FALSE
## 2                              FALSE
## 3                              FALSE
## 4                              FALSE
## 5                              FALSE
## 6                              FALSE
table(dat1b$IsElectric)
## 
##   Error   FALSE    TRUE Unknown 
##     950 9034348   25473     295
dat3= subset(dat1b, IsElectric==TRUE)
dim(dat3)
## [1] 25473    63
library(tibble)
library(dplyr)

# Create sorted table
sorted_tbl <- table(dat3$VehMMY) %>%
  sort(decreasing = TRUE) %>%
  as.data.frame() %>%
  as_tibble() %>%
  rename(VehMMY = Var1, Count = Freq)
DT::datatable(sorted_tbl)
write.csv(dat3, "EV_2017_2023CRIS.csv")

# Step 1: Filter to variables with ≤ 80 unique values
unique_counts <- sapply(dat3, function(x) length(unique(x)))
filtered_vars <- names(unique_counts[unique_counts <= 100])
dat_filtered <- dat3[, filtered_vars]

# Step 2: Reorder all values within each variable by frequency (even numeric treated as categorical)
dat_reordered <- as.data.frame(lapply(dat_filtered, function(x) {
  if (is.numeric(x)) {
    x <- factor(x)  # treat numeric as categorical
  }
  if (is.factor(x) || is.character(x)) {
    freq_order <- names(sort(table(x), decreasing = TRUE))
    x <- factor(x, levels = freq_order)
  }
  return(x)
}))


# Step 3: Show summary
dfSummary(dat_reordered,
          style = "grid",
          plain.ascii = FALSE,
          graph.col = FALSE, max.distinct.values = 100)
## ### Data Frame Summary  
## #### dat_reordered  
## **Dimensions:** 25473 x 49  
## **Duplicates:** 2  
## 
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | No | Variable                            | Stats / Values                  | Freqs (% of Valid) | Valid    | Missing |
## +====+=====================================+=================================+====================+==========+=========+
## | 1  | UnitNbr_Pr\                         | 1\. 2\                          | 12365 (51.5%)\     | 24024\   | 1449\   |
## |    | [factor]                            | 2\. 1\                          | 9479 (39.5%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. 3\                          | 1773 ( 7.4%)\      |          |         |
## |    |                                     | 4\. 4\                          | 304 ( 1.3%)\       |          |         |
## |    |                                     | 5\. 5\                          | 69 ( 0.3%)\        |          |         |
## |    |                                     | 6\. 6\                          | 19 ( 0.1%)\        |          |         |
## |    |                                     | 7\. 7\                          | 8 ( 0.0%)\         |          |         |
## |    |                                     | 8\. 8\                          | 5 ( 0.0%)\         |          |         |
## |    |                                     | 9\. 10                          | 2 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 2  | Year\                               | 1\. 2024\                       | 7911 (31.1%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. 2023\                       | 5979 (23.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 2022\                       | 4124 (16.2%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 2540 (10.0%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 1627 ( 6.4%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 1491 ( 5.9%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 1038 ( 4.1%)\      |          |         |
## |    |                                     | 8\. 2017                        | 763 ( 3.0%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 3  | Yr_Un\                              | 1\. 2024\                       | 7911 (31.1%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. 2023\                       | 5979 (23.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 2022\                       | 4124 (16.2%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 2540 (10.0%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 1627 ( 6.4%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 1491 ( 5.9%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 1038 ( 4.1%)\      |          |         |
## |    |                                     | 8\. 2017                        | 763 ( 3.0%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 4  | Yr_Pr\                              | 1\. 2024\                       | 7458 (31.0%)\      | 24024\   | 1449\   |
## |    | [factor]                            | 2\. 2023\                       | 5622 (23.4%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. 2022\                       | 3890 (16.2%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 2386 ( 9.9%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 1543 ( 6.4%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 1409 ( 5.9%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 995 ( 4.1%)\       |          |         |
## |    |                                     | 8\. 2017                        | 721 ( 3.0%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 5  | Prsn_Nbr\                           | 1\. 1                           | 24024 (100.0%)     | 24024\   | 1449\   |
## |    | [factor]                            |                                 |                    | (94.3%)  | (5.7%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 6  | Crash_Speed_Limit\                  | 1\. 45\                         | 4375 (17.2%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. 35\                         | 3688 (14.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 40\                         | 3076 (12.1%)\      |          |         |
## |    |                                     | 4\. 30\                         | 3068 (12.0%)\      |          |         |
## |    |                                     | 5\. 65\                         | 2067 ( 8.1%)\      |          |         |
## |    |                                     | 6\. 60\                         | 1765 ( 6.9%)\      |          |         |
## |    |                                     | 7\. -1\                         | 1491 ( 5.9%)\      |          |         |
## |    |                                     | 8\. 55\                         | 1455 ( 5.7%)\      |          |         |
## |    |                                     | 9\. 70\                         | 1384 ( 5.4%)\      |          |         |
## |    |                                     | 10\. 50\                        | 1253 ( 4.9%)\      |          |         |
## |    |                                     | 11\. 75\                        | 386 ( 1.5%)\       |          |         |
## |    |                                     | 12\. 5\                         | 373 ( 1.5%)\       |          |         |
## |    |                                     | 13\. 10\                        | 296 ( 1.2%)\       |          |         |
## |    |                                     | 14\. 15\                        | 272 ( 1.1%)\       |          |         |
## |    |                                     | 15\. 25\                        | 264 ( 1.0%)\       |          |         |
## |    |                                     | 16\. 20\                        | 228 ( 0.9%)\       |          |         |
## |    |                                     | 17\. 80\                        | 30 ( 0.1%)\        |          |         |
## |    |                                     | 18\. 39\                        | 1 ( 0.0%)\         |          |         |
## |    |                                     | 19\. 85                         | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 7  | Wthr_Cond_ID\                       | 1\. Clear\                      | 20134 (79.0%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Cloudy\                     | 3143 (12.3%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Rain\                       | 1887 ( 7.4%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 177 ( 0.7%)\       |          |         |
## |    |                                     | 5\. Fog\                        | 52 ( 0.2%)\        |          |         |
## |    |                                     | 6\. Sleet/Hail\                 | 30 ( 0.1%)\        |          |         |
## |    |                                     | 7\. Snow\                       | 22 ( 0.1%)\        |          |         |
## |    |                                     | 8\. Other (Explain In Narrati\  | 13 ( 0.1%)\        |          |         |
## |    |                                     | 9\. Severe Crosswinds\          | 12 ( 0.0%)\        |          |         |
## |    |                                     | 10\. Blowing Sand/Snow          | 3 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 8  | Light_Cond_ID\                      | 1\. Daylight\                   | 18689 (73.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Dark, Lighted\              | 4676 (18.4%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Dark, Not Lighted\          | 1252 ( 4.9%)\      |          |         |
## |    |                                     | 4\. Dusk\                       | 318 ( 1.2%)\       |          |         |
## |    |                                     | 5\. Dark, Unknown Lighting\     | 223 ( 0.9%)\       |          |         |
## |    |                                     | 6\. Dawn\                       | 178 ( 0.7%)\       |          |         |
## |    |                                     | 7\. Unknown\                    | 119 ( 0.5%)\       |          |         |
## |    |                                     | 8\. Other (Explain In Narrati   | 18 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 9  | Entr_Road_ID\                       | 1\. Not Applicable\             | 13966 (54.8%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Four Entering Roads\        | 5197 (20.4%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Three Entering Roads - T\   | 3526 (13.8%)\      |          |         |
## |    |                                     | 4\. Other (Explain In Narrati\  | 2177 ( 8.5%)\      |          |         |
## |    |                                     | 5\. Three Entering Roads - Y\   | 373 ( 1.5%)\       |          |         |
## |    |                                     | 6\. Six Entering Roads\         | 87 ( 0.3%)\        |          |         |
## |    |                                     | 7\. Five Entering Roads\        | 81 ( 0.3%)\        |          |         |
## |    |                                     | 8\. Traffic Circle\             | 45 ( 0.2%)\        |          |         |
## |    |                                     | 9\. Cloverleaf                  | 21 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 10 | Road_Type_ID\                       | 1\. 4 Or More Lanes, Undivide\  | 7108 (37.9%)\      | 18739\   | 6734\   |
## |    | [factor]                            | 2\. 2 Lane, 2 Way\              | 5836 (31.1%)\      | (73.6%)  | (26.4%) |
## |    |                                     | 3\. 4 Or More Lanes, Divided    | 5795 (30.9%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 11 | Road_Algn_ID\                       | 1\. Straight, Level\            | 21543 (84.6%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Straight, Grade\            | 1717 ( 6.7%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Curve, Level\               | 931 ( 3.7%)\       |          |         |
## |    |                                     | 4\. Straight, Hillcrest\        | 421 ( 1.7%)\       |          |         |
## |    |                                     | 5\. Curve, Grade\               | 407 ( 1.6%)\       |          |         |
## |    |                                     | 6\. Other (Explain In Narrati\  | 268 ( 1.1%)\       |          |         |
## |    |                                     | 7\. Curve, Hillcrest\           | 106 ( 0.4%)\       |          |         |
## |    |                                     | 8\. Unknown                     | 80 ( 0.3%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 12 | Surf_Cond_ID\                       | 1\. Dry\                        | 22566 (88.6%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Wet\                        | 2535 (10.0%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Unknown\                    | 175 ( 0.7%)\       |          |         |
## |    |                                     | 4\. Standing Water\             | 97 ( 0.4%)\        |          |         |
## |    |                                     | 5\. Ice\                        | 57 ( 0.2%)\        |          |         |
## |    |                                     | 6\. Sand, Mud, Dirt\            | 18 ( 0.1%)\        |          |         |
## |    |                                     | 7\. Other (Explain In Narrati\  | 13 ( 0.1%)\        |          |         |
## |    |                                     | 8\. Snow\                       | 8 ( 0.0%)\         |          |         |
## |    |                                     | 9\. Slush                       | 4 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 13 | Traffic_Cntl_ID\                    | 1\. Marked Lanes\               | 11520 (45.2%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Signal Light\               | 4878 (19.1%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. None\                       | 4194 (16.5%)\      |          |         |
## |    |                                     | 4\. Stop Sign\                  | 2313 ( 9.1%)\      |          |         |
## |    |                                     | 5\. Other (Explain In Narrati\  | 811 ( 3.2%)\       |          |         |
## |    |                                     | 6\. Center Stripe/Divider\      | 802 ( 3.1%)\       |          |         |
## |    |                                     | 7\. Yield Sign\                 | 384 ( 1.5%)\       |          |         |
## |    |                                     | 8\. Signal Light With Red Lig\  | 126 ( 0.5%)\       |          |         |
## |    |                                     | 9\. No Passing Zone\            | 81 ( 0.3%)\        |          |         |
## |    |                                     | 10\. Flashing Red Light\        | 73 ( 0.3%)\        |          |         |
## |    |                                     | 11\. Inoperative (Explain In N\ | 65 ( 0.3%)\        |          |         |
## |    |                                     | 12\. Officer\                   | 57 ( 0.2%)\        |          |         |
## |    |                                     | 13\. Flashing Yellow Light\     | 53 ( 0.2%)\        |          |         |
## |    |                                     | 14\. Warning Sign\              | 50 ( 0.2%)\        |          |         |
## |    |                                     | 15\. Crosswalk\                 | 28 ( 0.1%)\        |          |         |
## |    |                                     | 16\. Flagman\                   | 18 ( 0.1%)\        |          |         |
## |    |                                     | 17\. Bike Lane\                 | 14 ( 0.1%)\        |          |         |
## |    |                                     | 18\. Rr Gate/Signal             | 6 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 14 | Harm_Evnt_ID\                       | 1\. Motor Vehicle In Transpor\  | 21234 (83.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Fixed Object\               | 1878 ( 7.4%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Parked Car\                 | 1804 ( 7.1%)\      |          |         |
## |    |                                     | 4\. Pedestrian\                 | 146 ( 0.6%)\       |          |         |
## |    |                                     | 5\. Other Object\               | 138 ( 0.5%)\       |          |         |
## |    |                                     | 6\. Animal\                     | 115 ( 0.5%)\       |          |         |
## |    |                                     | 7\. Pedalcyclist\               | 75 ( 0.3%)\        |          |         |
## |    |                                     | 8\. Overturned\                 | 53 ( 0.2%)\        |          |         |
## |    |                                     | 9\. Other Non Collision\        | 28 ( 0.1%)\        |          |         |
## |    |                                     | 10\. Rr Train                   | 2 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 15 | Intrsct_Relat_ID\                   | 1\. Non Intersection\           | 13090 (51.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Intersection\               | 6282 (24.7%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Intersection Related\       | 4034 (15.8%)\      |          |         |
## |    |                                     | 4\. Driveway Access             | 2067 ( 8.1%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 16 | FHE_Collsn_ID\                      | 1\. Same Direction - Both Goi\  | 4459 (17.5%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. Same Direction - One Stra\  | 3555 (14.0%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Same Direction - Both Goi\  | 3423 (13.4%)\      |          |         |
## |    |                                     | 4\. Angle - Both Going Straig\  | 3293 (12.9%)\      |          |         |
## |    |                                     | 5\. One Motor Vehicle - Going\  | 2766 (10.9%)\      |          |         |
## |    |                                     | 6\. Opposite Direction - One \  | 2100 ( 8.2%)\      |          |         |
## |    |                                     | 7\. Angle - One Straight-One \  | 1271 ( 5.0%)\      |          |         |
## |    |                                     | 8\. Angle - One Straight-One \  | 643 ( 2.5%)\       |          |         |
## |    |                                     | 9\. One Motor Vehicle - Backi\  | 632 ( 2.5%)\       |          |         |
## |    |                                     | 10\. Same Direction - One Stra\ | 556 ( 2.2%)\       |          |         |
## |    |                                     | 11\. One Motor Vehicle - Other\ | 385 ( 1.5%)\       |          |         |
## |    |                                     | 12\. Same Direction - One Stra\ | 356 ( 1.4%)\       |          |         |
## |    |                                     | 13\. Opposite Direction - Both\ | 251 ( 1.0%)\       |          |         |
## |    |                                     | 14\. One Motor Vehicle - Turni\ | 234 ( 0.9%)\       |          |         |
## |    |                                     | 15\. One Motor Vehicle - Turni\ | 222 ( 0.9%)\       |          |         |
## |    |                                     | 16\. Other - One Straight-One \ | 188 ( 0.7%)\       |          |         |
## |    |                                     | 17\. Same Direction - Both Rig\ | 158 ( 0.6%)\       |          |         |
## |    |                                     | 18\. Same Direction - Both Lef\ | 126 ( 0.5%)\       |          |         |
## |    |                                     | 19\. Opposite Direction - One \ | 114 ( 0.4%)\       |          |         |
## |    |                                     | 20\. Angle - One Straight-One \ | 104 ( 0.4%)\       |          |         |
## |    |                                     | 21\. Other\                     | 87 ( 0.3%)\        |          |         |
## |    |                                     | 22\. Opposite Direction - One \ | 82 ( 0.3%)\        |          |         |
## |    |                                     | 23\. Angle - One Right Turn-On\ | 78 ( 0.3%)\        |          |         |
## |    |                                     | 24\. Opposite Direction - One \ | 64 ( 0.3%)\        |          |         |
## |    |                                     | 25\. Angle - One Left Turn-One\ | 60 ( 0.2%)\        |          |         |
## |    |                                     | 26\. Other - Both Backing\      | 59 ( 0.2%)\        |          |         |
## |    |                                     | 27\. Angle - One Straight-One \ | 34 ( 0.1%)\        |          |         |
## |    |                                     | 28\. Other - One Entering Or L\ | 31 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Angle - Both Left Turn\    | 30 ( 0.1%)\        |          |         |
## |    |                                     | 30\. Opposite Direction - Both\ | 25 ( 0.1%)\        |          |         |
## |    |                                     | 31\. Same Direction - One Righ\ | 24 ( 0.1%)\        |          |         |
## |    |                                     | 32\. Angle - One Right Turn-On\ | 21 ( 0.1%)\        |          |         |
## |    |                                     | 33\. Opposite Direction - One \ | 17 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Other - Both Entering Or \ | 8 ( 0.0%)\         |          |         |
## |    |                                     | 35\. Same Direction - One Left\ | 7 ( 0.0%)\         |          |         |
## |    |                                     | 36\. Opposite Direction - One \ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 37\. Opposite Direction - One \ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 38\. Angle - Both Right Turn\   | 1 ( 0.0%)\         |          |         |
## |    |                                     | 39\. Other - One Left Turn-One\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 40\. Other - One Right Turn-On\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 41\. Same Direction - One Righ  | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 17 | Obj_Struck_ID\                      | 1\. Not Applicable\             | 22282 (87.5%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Hit Median Barrier (Concr\  | 565 ( 2.2%)\       | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Hit Concrete Traffic Barr\  | 235 ( 0.9%)\       |          |         |
## |    |                                     | 4\. Hit Tree, Shrub, Landscap\  | 228 ( 0.9%)\       |          |         |
## |    |                                     | 5\. Overturned\                 | 210 ( 0.8%)\       |          |         |
## |    |                                     | 6\. Hit Guardrail\              | 199 ( 0.8%)\       |          |         |
## |    |                                     | 7\. Hit Other Fixed Object\     | 196 ( 0.8%)\       |          |         |
## |    |                                     | 8\. Hit Highway Sign\           | 187 ( 0.7%)\       |          |         |
## |    |                                     | 9\. Hit Retaining Wall\         | 178 ( 0.7%)\       |          |         |
## |    |                                     | 10\. Hit Fence\                 | 173 ( 0.7%)\       |          |         |
## |    |                                     | 11\. Hit Curb\                  | 150 ( 0.6%)\       |          |         |
## |    |                                     | 12\. Hit Luminaire Pole\        | 144 ( 0.6%)\       |          |         |
## |    |                                     | 13\. Other\                     | 118 ( 0.5%)\       |          |         |
## |    |                                     | 14\. Hit House, Building, Or B\ | 117 ( 0.5%)\       |          |         |
## |    |                                     | 15\. Hit Utility Pole\          | 97 ( 0.4%)\        |          |         |
## |    |                                     | 16\. Hit Attenuation Device\    | 55 ( 0.2%)\        |          |         |
## |    |                                     | 17\. Hit Traffic Signal Pole O\ | 50 ( 0.2%)\        |          |         |
## |    |                                     | 18\. Ditch\                     | 41 ( 0.2%)\        |          |         |
## |    |                                     | 19\. Hit Mailbox\               | 41 ( 0.2%)\        |          |         |
## |    |                                     | 20\. Fire Hydrant\              | 39 ( 0.2%)\        |          |         |
## |    |                                     | 21\. Hit Object From Another V\ | 28 ( 0.1%)\        |          |         |
## |    |                                     | 22\. Hit Commercial Sign\       | 25 ( 0.1%)\        |          |         |
## |    |                                     | 23\. Hit Work Zone Barricade, \ | 23 ( 0.1%)\        |          |         |
## |    |                                     | 24\. Embankment\                | 13 ( 0.1%)\        |          |         |
## |    |                                     | 25\. Hit Culvert-Headwall\      | 13 ( 0.1%)\        |          |         |
## |    |                                     | 26\. Hit Side Of Bridge (Bridg\ | 13 ( 0.1%)\        |          |         |
## |    |                                     | 27\. Hit Previously Wrecked\    | 12 ( 0.0%)\        |          |         |
## |    |                                     | 28\. Hit Pier Or Support At Un\ | 7 ( 0.0%)\         |          |         |
## |    |                                     | 29\. Hit Hole In Road\          | 6 ( 0.0%)\         |          |         |
## |    |                                     | 30\. Jack-Knifed\               | 6 ( 0.0%)\         |          |         |
## |    |                                     | 31\. Hit Delineator Or Marker \ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 32\. Hit Fallen Trees Or Debri\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 33\. Hit Overhead Signal Light\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 34\. Person Fell Or Jumped Fro\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 35\. Hit Train Moving Forward\  | 2 ( 0.0%)\         |          |         |
## |    |                                     | 36\. Hit Bus Stop Structure (B\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 37\. Hit By Fallen/Blowing Roc\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 38\. Hit Other Machinery\       | 1 ( 0.0%)\         |          |         |
## |    |                                     | 39\. Hit Railroad Crossing Gat\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 40\. Hit Top Of Underpass Or T  | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 18 | Othr_Factr_ID\                      | 1\. Not Applicable·\            | 10179 (40.0%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Vehicle Changing Lanes·\    | 2339 ( 9.2%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Attention Diverted From D\  | 2330 ( 9.1%)\      |          |         |
## |    |                                     | 4\. Slowing/Stopping-For Traf\  | 2317 ( 9.1%)\      |          |         |
## |    |                                     | 5\. Slowing/Stopping - For Of\  | 1790 ( 7.0%)\      |          |         |
## |    |                                     | 6\. One Vehicle Leaving Drive\  | 1385 ( 5.4%)\      |          |         |
## |    |                                     | 7\. Construction - Within Pos\  | 1025 ( 4.0%)\      |          |         |
## |    |                                     | 8\. One Vehicle Entering Driv\  | 673 ( 2.6%)\       |          |         |
## |    |                                     | 9\. One Vehicle Backward From\  | 575 ( 2.3%)\       |          |         |
## |    |                                     | 10\. Lost Control Or Skidded (\ | 482 ( 1.9%)\       |          |         |
## |    |                                     | 11\. Slowing/Stopping-Reason N\ | 406 ( 1.6%)\       |          |         |
## |    |                                     | 12\. Slowing/Stopping-To Make \ | 232 ( 0.9%)\       |          |         |
## |    |                                     | 13\. Slowing/Stopping-To Make \ | 215 ( 0.8%)\       |          |         |
## |    |                                     | 14\. Construction-Within Poste\ | 174 ( 0.7%)\       |          |         |
## |    |                                     | 15\. Swerved Or Veered-Reason \ | 171 ( 0.7%)\       |          |         |
## |    |                                     | 16\. Vehicle Passing Or Attemp\ | 158 ( 0.6%)\       |          |         |
## |    |                                     | 17\. Swerved Or Veered-Avoidin\ | 147 ( 0.6%)\       |          |         |
## |    |                                     | 18\. One Vehicle Forward From \ | 112 ( 0.4%)\       |          |         |
## |    |                                     | 19\. One Vehicle Parked Improp\ | 76 ( 0.3%)\        |          |         |
## |    |                                     | 20\. School Bus Related Crash·\ | 69 ( 0.3%)\        |          |         |
## |    |                                     | 21\. Swerved Or Veered-Avoidin\ | 67 ( 0.3%)\        |          |         |
## |    |                                     | 22\. Vehicle Passing Or Attemp\ | 61 ( 0.2%)\        |          |         |
## |    |                                     | 23\. Slowing/Stopping-To Avoid\ | 50 ( 0.2%)\        |          |         |
## |    |                                     | 24\. Swerved Or Veered-Avoidin\ | 44 ( 0.2%)\        |          |         |
## |    |                                     | 25\. Swerved Or Veered-Avoidin\ | 43 ( 0.2%)\        |          |         |
## |    |                                     | 26\. Vision Obstructed By Head\ | 42 ( 0.2%)\        |          |         |
## |    |                                     | 27\. Construction-In Other Con\ | 33 ( 0.1%)\        |          |         |
## |    |                                     | 28\. Open Door Or Object Proje\ | 31 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Swerved Or Veered - Avoid\ | 31 ( 0.1%)\        |          |         |
## |    |                                     | 30\. Vision Obstructed By Movi\ | 27 ( 0.1%)\        |          |         |
## |    |                                     | 31\. Slowing/Stopping-For Obje\ | 25 ( 0.1%)\        |          |         |
## |    |                                     | 32\. Slowing/Stopping-For Pede\ | 22 ( 0.1%)\        |          |         |
## |    |                                     | 33\. Foot Slipped Off Brake Or\ | 21 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Slowing/Stopping-For Anim\ | 19 ( 0.1%)\        |          |         |
## |    |                                     | 35\. Swerved Or Veered-Avoidin\ | 17 ( 0.1%)\        |          |         |
## |    |                                     | 36\. Vision Obstructed By Stan\ | 16 ( 0.1%)\        |          |         |
## |    |                                     | 37\. Vision Obstructed By Othe\ | 15 ( 0.1%)\        |          |         |
## |    |                                     | 38\. Slowing/Stopping-For Vehi\ | 14 ( 0.1%)\        |          |         |
## |    |                                     | 39\. Slowing/Stopping-For Surf\ | 13 ( 0.1%)\        |          |         |
## |    |                                     | 40\. Slowing/Stopping-For Vehi\ | 7 ( 0.0%)\         |          |         |
## |    |                                     | 41\. Swerved Or Veered-For Sur\ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 42\. Swerved Or Veered-Avoidin\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 43\. Construction - In Other C\ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 44\. Crash Occurred On A Beach\ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 45\. Vision Obstructed By Tree\ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 46\. Gusty Winds·\              | 1 ( 0.0%)\         |          |         |
## |    |                                     | 47\. Passenger Interfered With\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 48\. Swerved Or Veered-Avoidin\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 49\. Swerved Or Veered - For O\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 50\. Vision Obstructed By Hill  | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 19 | Road_Part_Adj_ID\                   | 1\. Main/Proper Lane\           | 20041 (78.7%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Service/Frontage Road\      | 2703 (10.6%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Other (Explain In Narrati\  | 2135 ( 8.4%)\      |          |         |
## |    |                                     | 4\. Exit/Off Ramp\              | 265 ( 1.0%)\       |          |         |
## |    |                                     | 5\. Entrance/On Ramp\           | 225 ( 0.9%)\       |          |         |
## |    |                                     | 6\. Connector/Flyover           | 104 ( 0.4%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 20 | Road_Cls_ID\                        | 1\. City Street\                | 9844 (38.6%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. Us & State Highways\        | 5255 (20.6%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Interstate\                 | 4254 (16.7%)\      |          |         |
## |    |                                     | 4\. Non Trafficway\             | 2127 ( 8.4%)\      |          |         |
## |    |                                     | 5\. Farm To Market\             | 1773 ( 7.0%)\      |          |         |
## |    |                                     | 6\. County Road\                | 1311 ( 5.1%)\      |          |         |
## |    |                                     | 7\. Tollway\                    | 895 ( 3.5%)\       |          |         |
## |    |                                     | 8\. Other Roads\                | 13 ( 0.1%)\        |          |         |
## |    |                                     | 9\. Toll Bridges                | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 21 | Road_Relat_ID\                      | 1\. On Roadway\                 | 21438 (84.2%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Not Applicable\             | 2120 ( 8.3%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Off Roadway\                | 1365 ( 5.4%)\      |          |         |
## |    |                                     | 4\. Median\                     | 497 ( 2.0%)\       |          |         |
## |    |                                     | 5\. Shoulder                    | 53 ( 0.2%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 22 | Crash_Sev_ID\                       | 1\. Not Injured\                | 17621 (69.2%)\     | 25471\   | 2\      |
## |    | [factor]                            | 2\. Possible Injury\            | 3675 (14.4%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Non-Incapacitating\         | 2634 (10.3%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 1084 ( 4.3%)\      |          |         |
## |    |                                     | 5\. Incapacitating Injury\      | 398 ( 1.6%)\       |          |         |
## |    |                                     | 6\. Killed                      | 59 ( 0.2%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 23 | Pop_Group_ID\                       | 1\. 250,000 Pop And Over\       | 12071 (47.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Rural\                      | 4385 (17.2%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 100,000 - 249,999 Pop\      | 3186 (12.5%)\      |          |         |
## |    |                                     | 4\. 50,000 - 99,999 Pop\        | 2046 ( 8.0%)\      |          |         |
## |    |                                     | 5\. 25,000 - 49,999 Pop\        | 1336 ( 5.2%)\      |          |         |
## |    |                                     | 6\. 10,000 - 24,999 Pop\        | 1217 ( 4.8%)\      |          |         |
## |    |                                     | 7\. 5,000 - 9,999 Pop\          | 559 ( 2.2%)\       |          |         |
## |    |                                     | 8\. 2,500 - 4,999 Pop\          | 393 ( 1.5%)\       |          |         |
## |    |                                     | 9\. Town Under 2,499 Pop        | 280 ( 1.1%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 24 | Day_of_Week\                        | 1\. FRI\                        | 4149 (16.3%)\      | 25473\   | 0\      |
## |    | [factor]                            | 2\. WED\                        | 3942 (15.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. THU\                        | 3833 (15.0%)\      |          |         |
## |    |                                     | 4\. TUE\                        | 3785 (14.9%)\      |          |         |
## |    |                                     | 5\. SAT\                        | 3540 (13.9%)\      |          |         |
## |    |                                     | 6\. MON\                        | 3533 (13.9%)\      |          |         |
## |    |                                     | 7\. SUN                         | 2691 (10.6%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 25 | Rural_Urban_Type_ID\                | 1\. Urbanized (200,000+)\       | 9062 (80.1%)\      | 11313\   | 14160\  |
## |    | [factor]                            | 2\. Rural (<5000)\              | 969 ( 8.6%)\       | (44.4%)  | (55.6%) |
## |    |                                     | 3\. Large Urban (50,000-199,9\  | 796 ( 7.0%)\       |          |         |
## |    |                                     | 4\. Small Urban (5000-49,999)   | 486 ( 4.3%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 26 | Func_Sys_ID\                        | 1\. Rural Interstate\           | 4215 (66.8%)\      | 6309\    | 19164\  |
## |    | [factor]                            | 2\. Rural Prin Arterial\        | 2072 (32.8%)\      | (24.8%)  | (75.2%) |
## |    |                                     | 3\. Rural Minor Arterial\       | 20 ( 0.3%)\        |          |         |
## |    |                                     | 4\. Rural Major Coll            | 2 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 27 | Veh_Mod_Year\                       | 1\. 2023\                       | 4192 (16.6%)\      | 25244\   | 229\    |
## |    | [factor]                            | 2\. 2022\                       | 3491 (13.8%)\      | (99.1%)  | (0.9%)  |
## |    |                                     | 3\. 2021\                       | 3333 (13.2%)\      |          |         |
## |    |                                     | 4\. 2018\                       | 2753 (10.9%)\      |          |         |
## |    |                                     | 5\. 2020\                       | 2079 ( 8.2%)\      |          |         |
## |    |                                     | 6\. 2019\                       | 1848 ( 7.3%)\      |          |         |
## |    |                                     | 7\. 2017\                       | 1420 ( 5.6%)\      |          |         |
## |    |                                     | 8\. 2024\                       | 1203 ( 4.8%)\      |          |         |
## |    |                                     | 9\. 2016\                       | 1054 ( 4.2%)\      |          |         |
## |    |                                     | 10\. 2015\                      | 968 ( 3.8%)\       |          |         |
## |    |                                     | 11\. 2014\                      | 812 ( 3.2%)\       |          |         |
## |    |                                     | 12\. 2013\                      | 780 ( 3.1%)\       |          |         |
## |    |                                     | 13\. 2012\                      | 424 ( 1.7%)\       |          |         |
## |    |                                     | 14\. 2011\                      | 213 ( 0.8%)\       |          |         |
## |    |                                     | 15\. 2010\                      | 115 ( 0.5%)\       |          |         |
## |    |                                     | 16\. 2008\                      | 112 ( 0.4%)\       |          |         |
## |    |                                     | 17\. 2009\                      | 105 ( 0.4%)\       |          |         |
## |    |                                     | 18\. 2007\                      | 80 ( 0.3%)\        |          |         |
## |    |                                     | 19\. 2025\                      | 65 ( 0.3%)\        |          |         |
## |    |                                     | 20\. 2006\                      | 50 ( 0.2%)\        |          |         |
## |    |                                     | 21\. 2005\                      | 22 ( 0.1%)\        |          |         |
## |    |                                     | 22\. 2003\                      | 16 ( 0.1%)\        |          |         |
## |    |                                     | 23\. 2004\                      | 16 ( 0.1%)\        |          |         |
## |    |                                     | 24\. 2000\                      | 15 ( 0.1%)\        |          |         |
## |    |                                     | 25\. 2002\                      | 12 ( 0.0%)\        |          |         |
## |    |                                     | 26\. 1999\                      | 11 ( 0.0%)\        |          |         |
## |    |                                     | 27\. 2001\                      | 10 ( 0.0%)\        |          |         |
## |    |                                     | 28\. 1993\                      | 7 ( 0.0%)\         |          |         |
## |    |                                     | 29\. 1988\                      | 5 ( 0.0%)\         |          |         |
## |    |                                     | 30\. 1996\                      | 5 ( 0.0%)\         |          |         |
## |    |                                     | 31\. 1998\                      | 5 ( 0.0%)\         |          |         |
## |    |                                     | 32\. 1990\                      | 4 ( 0.0%)\         |          |         |
## |    |                                     | 33\. 1991\                      | 4 ( 0.0%)\         |          |         |
## |    |                                     | 34\. 1994\                      | 4 ( 0.0%)\         |          |         |
## |    |                                     | 35\. 1992\                      | 3 ( 0.0%)\         |          |         |
## |    |                                     | 36\. 1997\                      | 3 ( 0.0%)\         |          |         |
## |    |                                     | 37\. 1995\                      | 2 ( 0.0%)\         |          |         |
## |    |                                     | 38\. 1980\                      | 1 ( 0.0%)\         |          |         |
## |    |                                     | 39\. 1982\                      | 1 ( 0.0%)\         |          |         |
## |    |                                     | 40\. 1989                       | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 28 | Veh_Color_ID\                       | 1\. White\                      | 7761 (30.6%)\      | 25342\   | 131\    |
## |    | [factor]                            | 2\. Black\                      | 4947 (19.5%)\      | (99.5%)  | (0.5%)  |
## |    |                                     | 3\. Gray\                       | 4503 (17.8%)\      |          |         |
## |    |                                     | 4\. Blue\                       | 2956 (11.7%)\      |          |         |
## |    |                                     | 5\. Red\                        | 2525 (10.0%)\      |          |         |
## |    |                                     | 6\. Silver\                     | 1669 ( 6.6%)\      |          |         |
## |    |                                     | 7\. Unknown\                    | 277 ( 1.1%)\       |          |         |
## |    |                                     | 8\. Green\                      | 172 ( 0.7%)\       |          |         |
## |    |                                     | 9\. Maroon\                     | 131 ( 0.5%)\       |          |         |
## |    |                                     | 10\. Brown\                     | 73 ( 0.3%)\        |          |         |
## |    |                                     | 11\. Multicolored\              | 62 ( 0.2%)\        |          |         |
## |    |                                     | 12\. Orange\                    | 53 ( 0.2%)\        |          |         |
## |    |                                     | 13\. Yellow\                    | 52 ( 0.2%)\        |          |         |
## |    |                                     | 14\. Gold\                      | 34 ( 0.1%)\        |          |         |
## |    |                                     | 15\. Tan\                       | 31 ( 0.1%)\        |          |         |
## |    |                                     | 16\. Beige\                     | 28 ( 0.1%)\        |          |         |
## |    |                                     | 17\. Turquoise(Blue)\           | 23 ( 0.1%)\        |          |         |
## |    |                                     | 18\. Purple\                    | 20 ( 0.1%)\        |          |         |
## |    |                                     | 19\. Pink\                      | 8 ( 0.0%)\         |          |         |
## |    |                                     | 20\. Teal(Green)\               | 6 ( 0.0%)\         |          |         |
## |    |                                     | 21\. Bronze\                    | 5 ( 0.0%)\         |          |         |
## |    |                                     | 22\. Other (Explain In Narrati\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 23\. Copper\                    | 2 ( 0.0%)\         |          |         |
## |    |                                     | 24\. Camouflage                 | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 29 | Veh_Make_ID\                        | 1\. Tesla\                      | 17936 (70.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Chevrolet\                  | 2390 ( 9.4%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Hyundai\                    | 1514 ( 5.9%)\      |          |         |
## |    |                                     | 4\. Toyota\                     | 1212 ( 4.8%)\      |          |         |
## |    |                                     | 5\. Nissan\                     | 957 ( 3.8%)\       |          |         |
## |    |                                     | 6\. Bmw\                        | 563 ( 2.2%)\       |          |         |
## |    |                                     | 7\. Kia\                        | 353 ( 1.4%)\       |          |         |
## |    |                                     | 8\. Honda\                      | 201 ( 0.8%)\       |          |         |
## |    |                                     | 9\. Volkswagen\                 | 85 ( 0.3%)\        |          |         |
## |    |                                     | 10\. Gm\                        | 62 ( 0.2%)\        |          |         |
## |    |                                     | 11\. Cadillac\                  | 44 ( 0.2%)\        |          |         |
## |    |                                     | 12\. Zero Motorcycles Inc\      | 43 ( 0.2%)\        |          |         |
## |    |                                     | 13\. International\             | 35 ( 0.1%)\        |          |         |
## |    |                                     | 14\. Electric Vehicle Technolo\ | 20 ( 0.1%)\        |          |         |
## |    |                                     | 15\. Mitsubishi\                | 17 ( 0.1%)\        |          |         |
## |    |                                     | 16\. Fisker Automotive\         | 16 ( 0.1%)\        |          |         |
## |    |                                     | 17\. Global Electric Motors\    | 15 ( 0.1%)\        |          |         |
## |    |                                     | 18\. Porsche\                   | 4 ( 0.0%)\         |          |         |
## |    |                                     | 19\. Ford\                      | 2 ( 0.0%)\         |          |         |
## |    |                                     | 20\. New Flyer\                 | 2 ( 0.0%)\         |          |         |
## |    |                                     | 21\. Smart\                     | 1 ( 0.0%)\         |          |         |
## |    |                                     | 22\. Smith Electric             | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 30 | Veh_Mod_ID\                         | 1\. Model 3\                    | 6667 (30.7%)\      | 21730\   | 3743\   |
## |    | [factor]                            | 2\. Model S\                    | 3367 (15.5%)\      | (85.3%)  | (14.7%) |
## |    |                                     | 3\. Unknown\                    | 2885 (13.3%)\      |          |         |
## |    |                                     | 4\. Volt\                       | 1518 ( 7.0%)\      |          |         |
## |    |                                     | 5\. Model X\                    | 1285 ( 5.9%)\      |          |         |
## |    |                                     | 6\. Rav4 Ev\                    | 1079 ( 5.0%)\      |          |         |
## |    |                                     | 7\. Leaf\                       | 940 ( 4.3%)\       |          |         |
## |    |                                     | 8\. Ioniq\                      | 810 ( 3.7%)\       |          |         |
## |    |                                     | 9\. Bolt Ev\                    | 784 ( 3.6%)\       |          |         |
## |    |                                     | 10\. Kona\                      | 704 ( 3.2%)\       |          |         |
## |    |                                     | 11\. I3\                        | 418 ( 1.9%)\       |          |         |
## |    |                                     | 12\. Soul Ev\                   | 182 ( 0.8%)\       |          |         |
## |    |                                     | 13\. Soul\                      | 171 ( 0.8%)\       |          |         |
## |    |                                     | 14\. Clarity\                   | 115 ( 0.5%)\       |          |         |
## |    |                                     | 15\. I8\                        | 115 ( 0.5%)\       |          |         |
## |    |                                     | 16\. Prius Prime\               | 102 ( 0.5%)\       |          |         |
## |    |                                     | 17\. Spark Ev\                  | 87 ( 0.4%)\        |          |         |
## |    |                                     | 18\. E-Golf\                    | 85 ( 0.4%)\        |          |         |
## |    |                                     | 19\. Fit Ev\                    | 63 ( 0.3%)\        |          |         |
## |    |                                     | 20\. Ev1\                       | 62 ( 0.3%)\        |          |         |
## |    |                                     | 21\. Elr\                       | 44 ( 0.2%)\        |          |         |
## |    |                                     | 22\. Roadster\                  | 39 ( 0.2%)\        |          |         |
## |    |                                     | 23\. Estar\                     | 35 ( 0.2%)\        |          |         |
## |    |                                     | 24\. Mirai\                     | 24 ( 0.1%)\        |          |         |
## |    |                                     | 25\. Ev\                        | 21 ( 0.1%)\        |          |         |
## |    |                                     | 26\. Altra\                     | 17 ( 0.1%)\        |          |         |
## |    |                                     | 27\. I Miev\                    | 17 ( 0.1%)\        |          |         |
## |    |                                     | 28\. C Evolution\               | 11 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Karma\                     | 11 ( 0.1%)\        |          |         |
## |    |                                     | 30\. 530E\                      | 10 ( 0.0%)\        |          |         |
## |    |                                     | 31\. Dsr\                       | 9 ( 0.0%)\         |          |         |
## |    |                                     | 32\. Active E\                  | 8 ( 0.0%)\         |          |         |
## |    |                                     | 33\. Scion Iq Electric\         | 7 ( 0.0%)\         |          |         |
## |    |                                     | 34\. Sr\                        | 7 ( 0.0%)\         |          |         |
## |    |                                     | 35\. 918\                       | 4 ( 0.0%)\         |          |         |
## |    |                                     | 36\. Street\                    | 4 ( 0.0%)\         |          |         |
## |    |                                     | 37\. Classic\                   | 3 ( 0.0%)\         |          |         |
## |    |                                     | 38\. S\                         | 3 ( 0.0%)\         |          |         |
## |    |                                     | 39\. E6\                        | 2 ( 0.0%)\         |          |         |
## |    |                                     | 40\. Ev Plus\                   | 2 ( 0.0%)\         |          |         |
## |    |                                     | 41\. Sport\                     | 2 ( 0.0%)\         |          |         |
## |    |                                     | 42\. Think Neighbor\            | 2 ( 0.0%)\         |          |         |
## |    |                                     | 43\. 330E\                      | 1 ( 0.0%)\         |          |         |
## |    |                                     | 44\. 825\                       | 1 ( 0.0%)\         |          |         |
## |    |                                     | 45\. Dirt\                      | 1 ( 0.0%)\         |          |         |
## |    |                                     | 46\. Ds\                        | 1 ( 0.0%)\         |          |         |
## |    |                                     | 47\. E4\                        | 1 ( 0.0%)\         |          |         |
## |    |                                     | 48\. Em 1400/1400 Lsv\          | 1 ( 0.0%)\         |          |         |
## |    |                                     | 49\. Fortwo\                    | 1 ( 0.0%)\         |          |         |
## |    |                                     | 50\. Fx\                        | 1 ( 0.0%)\         |          |         |
## |    |                                     | 51\. Spark                      | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 31 | Veh_Body_Styl_ID\                   | 1\. Passenger Car, 4-Door\      | 20495 (80.5%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Sport Utility Vehicle\      | 3594 (14.1%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Passenger Car, 2-Door\      | 917 ( 3.6%)\       |          |         |
## |    |                                     | 4\. Unknown\                    | 151 ( 0.6%)\       |          |         |
## |    |                                     | 5\. Pickup\                     | 97 ( 0.4%)\        |          |         |
## |    |                                     | 6\. Motorcycle\                 | 48 ( 0.2%)\        |          |         |
## |    |                                     | 7\. Truck\                      | 41 ( 0.2%)\        |          |         |
## |    |                                     | 8\. Van\                        | 32 ( 0.1%)\        |          |         |
## |    |                                     | 9\. Nev-Neighborhood Electric\  | 28 ( 0.1%)\        |          |         |
## |    |                                     | 10\. Other (Explain In Narrati\ | 24 ( 0.1%)\        |          |         |
## |    |                                     | 11\. Truck Tractor\             | 20 ( 0.1%)\        |          |         |
## |    |                                     | 12\. Bus\                       | 14 ( 0.1%)\        |          |         |
## |    |                                     | 13\. Police Car/Truck\          | 5 ( 0.0%)\         |          |         |
## |    |                                     | 14\. Ambulance\                 | 3 ( 0.0%)\         |          |         |
## |    |                                     | 15\. Yellow School Bus\         | 3 ( 0.0%)\         |          |         |
## |    |                                     | 16\. Farm Equipment             | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 32 | Emer_Respndr_Fl\                    | 1\. N\                          | 25462 (100.0%)\    | 25473\   | 0\      |
## |    | [factor]                            | 2\. Y                           | 11 (  0.0%)        | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 33 | Contrib_Factr_1_ID\                 | 1\. None\                       | 15241 (61.8%)\     | 24674\   | 799\    |
## |    | [factor]                            | 2\. Failed To Control Speed\    | 1401 ( 5.7%)\      | (96.9%)  | (3.1%)  |
## |    |                                     | 3\. Other (Explain In Narrati\  | 943 ( 3.8%)\       |          |         |
## |    |                                     | 4\. Driver Inattention\         | 913 ( 3.7%)\       |          |         |
## |    |                                     | 5\. Changed Lane When Unsafe\   | 805 ( 3.3%)\       |          |         |
## |    |                                     | 6\. Failed To Yield Right Of \  | 734 ( 3.0%)\       |          |         |
## |    |                                     | 7\. Failed To Yield Right Of \  | 548 ( 2.2%)\       |          |         |
## |    |                                     | 8\. Failed To Drive In Single\  | 489 ( 2.0%)\       |          |         |
## |    |                                     | 9\. Disregard Stop And Go Sig\  | 365 ( 1.5%)\       |          |         |
## |    |                                     | 10\. Unsafe Speed\              | 345 ( 1.4%)\       |          |         |
## |    |                                     | 11\. Failed To Yield Right Of \ | 313 ( 1.3%)\       |          |         |
## |    |                                     | 12\. Backed Without Safety\     | 248 ( 1.0%)\       |          |         |
## |    |                                     | 13\. Faulty Evasive Action\     | 218 ( 0.9%)\       |          |         |
## |    |                                     | 14\. Followed Too Closely\      | 215 ( 0.9%)\       |          |         |
## |    |                                     | 15\. Disregard Stop Sign Or Li\ | 214 ( 0.9%)\       |          |         |
## |    |                                     | 16\. Turned When Unsafe\        | 171 ( 0.7%)\       |          |         |
## |    |                                     | 17\. Failed To Yield Right Of \ | 133 ( 0.5%)\       |          |         |
## |    |                                     | 18\. Under Influence - Alcohol\ | 124 ( 0.5%)\       |          |         |
## |    |                                     | 19\. Turned Improperly - Wrong\ | 122 ( 0.5%)\       |          |         |
## |    |                                     | 20\. Animal On Road - Wild\     | 105 ( 0.4%)\       |          |         |
## |    |                                     | 21\. Distraction In Vehicle\    | 89 ( 0.4%)\        |          |         |
## |    |                                     | 22\. Fatigued Or Asleep\        | 75 ( 0.3%)\        |          |         |
## |    |                                     | 23\. Failed To Pass To Left Sa\ | 60 ( 0.2%)\        |          |         |
## |    |                                     | 24\. Had Been Drinking\         | 58 ( 0.2%)\        |          |         |
## |    |                                     | 25\. Failed To Yield Right Of \ | 50 ( 0.2%)\        |          |         |
## |    |                                     | 26\. Turned Improperly - Wide \ | 46 ( 0.2%)\        |          |         |
## |    |                                     | 27\. Disregard Turn Marks At I\ | 45 ( 0.2%)\        |          |         |
## |    |                                     | 28\. Failed To Yield Right Of \ | 44 ( 0.2%)\        |          |         |
## |    |                                     | 29\. Animal On Road - Domestic\ | 42 ( 0.2%)\        |          |         |
## |    |                                     | 30\. Ill (Explain In Narrative\ | 38 ( 0.2%)\        |          |         |
## |    |                                     | 31\. Failed To Yield Right Of \ | 37 ( 0.1%)\        |          |         |
## |    |                                     | 32\. Failed To Stop At Proper \ | 36 ( 0.1%)\        |          |         |
## |    |                                     | 33\. Failed To Heed Warning Si\ | 30 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Impaired Visibility (Expl\ | 30 ( 0.1%)\        |          |         |
## |    |                                     | 35\. Failed To Pass To Right S\ | 26 ( 0.1%)\        |          |         |
## |    |                                     | 36\. Parked In Traffic Lane\    | 25 ( 0.1%)\        |          |         |
## |    |                                     | 37\. Improper Start From Parke\ | 24 ( 0.1%)\        |          |         |
## |    |                                     | 38\. Road Rage\                 | 23 ( 0.1%)\        |          |         |
## |    |                                     | 39\. Speeding - (Overlimit)\    | 22 ( 0.1%)\        |          |         |
## |    |                                     | 40\. Disabled In Traffic Lane\  | 21 ( 0.1%)\        |          |         |
## |    |                                     | 41\. Passed On Right Shoulder\  | 16 ( 0.1%)\        |          |         |
## |    |                                     | 42\. Under Influence - Drug\    | 14 ( 0.1%)\        |          |         |
## |    |                                     | 43\. Wrong Way - One Way Road\  | 14 ( 0.1%)\        |          |         |
## |    |                                     | 44\. Cell/Mobile Device Use - \ | 13 ( 0.1%)\        |          |         |
## |    |                                     | 45\. Fleeing Or Evading Police\ | 13 ( 0.1%)\        |          |         |
## |    |                                     | 46\. Passed In No Passing Lane\ | 13 ( 0.1%)\        |          |         |
## |    |                                     | 47\. Failed To Give Half Of Ro\ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 48\. Failed To Yield Right Of \ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 49\. Overtake And Pass Insuffi\ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 50\. Turned Improperly - Cut C\ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 51\. Wrong Side - Not Passing\  | 10 ( 0.0%)\        |          |         |
## |    |                                     | 52\. Opened Door Into Traffic \ | 9 ( 0.0%)\         |          |         |
## |    |                                     | 53\. Drove On Improved Shoulde\ | 7 ( 0.0%)\         |          |         |
## |    |                                     | 54\. Disregard Warning Sign At\ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 55\. Drove Without Headlights\  | 6 ( 0.0%)\         |          |         |
## |    |                                     | 56\. Failed To Signal Or Gave \ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 57\. Cell/Mobile Device Use - \ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 58\. Failed To Slow Or Move Ov\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 59\. Pedestrian Failed To Yiel\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 60\. Load Not Secured\          | 4 ( 0.0%)\         |          |         |
## |    |                                     | 61\. Handicapped Driver (Expla\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 62\. Cell/Mobile Device Use - \ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 63\. Failed To Stop For School\ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 64\. Fire In Vehicle\           | 2 ( 0.0%)\         |          |         |
## |    |                                     | 65\. Parked And Failed To Set \ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 66\. Parked Without Lights\     | 2 ( 0.0%)\         |          |         |
## |    |                                     | 67\. Taking Medication (Explai\ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 68\. Wrong Side - Approach Or \ | 2 ( 0.0%)\         |          |         |
## |    |                                     | 69\. Cell/Mobile Device Use -   | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 34 | Contrib_Factr_2_ID\                 | 1\. Driver Inattention\         | 299 (25.4%)\       | 1176\    | 24297\  |
## |    | [factor]                            | 2\. Failed To Control Speed\    | 150 (12.8%)\       | (4.6%)   | (95.4%) |
## |    |                                     | 3\. Failed To Drive In Single\  | 90 ( 7.7%)\        |          |         |
## |    |                                     | 4\. Faulty Evasive Action\      | 72 ( 6.1%)\        |          |         |
## |    |                                     | 5\. Other (Explain In Narrati\  | 54 ( 4.6%)\        |          |         |
## |    |                                     | 6\. Under Influence - Alcohol\  | 51 ( 4.3%)\        |          |         |
## |    |                                     | 7\. Distraction In Vehicle\     | 44 ( 3.7%)\        |          |         |
## |    |                                     | 8\. Turned When Unsafe\         | 34 ( 2.9%)\        |          |         |
## |    |                                     | 9\. Changed Lane When Unsafe\   | 32 ( 2.7%)\        |          |         |
## |    |                                     | 10\. Unsafe Speed\              | 32 ( 2.7%)\        |          |         |
## |    |                                     | 11\. Failed To Yield Right Of \ | 31 ( 2.6%)\        |          |         |
## |    |                                     | 12\. Followed Too Closely\      | 31 ( 2.6%)\        |          |         |
## |    |                                     | 13\. Had Been Drinking\         | 28 ( 2.4%)\        |          |         |
## |    |                                     | 14\. Failed To Yield Right Of \ | 23 ( 2.0%)\        |          |         |
## |    |                                     | 15\. Impaired Visibility (Expl\ | 23 ( 2.0%)\        |          |         |
## |    |                                     | 16\. Fatigued Or Asleep\        | 17 ( 1.4%)\        |          |         |
## |    |                                     | 17\. Disregard Stop Sign Or Li\ | 12 ( 1.0%)\        |          |         |
## |    |                                     | 18\. Backed Without Safety\     | 10 ( 0.9%)\        |          |         |
## |    |                                     | 19\. Cell/Mobile Device Use - \ | 10 ( 0.9%)\        |          |         |
## |    |                                     | 20\. Turned Improperly - Wide \ | 10 ( 0.9%)\        |          |         |
## |    |                                     | 21\. Failed To Yield Right Of \ | 9 ( 0.8%)\         |          |         |
## |    |                                     | 22\. Disregard Stop And Go Sig\ | 8 ( 0.7%)\         |          |         |
## |    |                                     | 23\. Speeding - (Overlimit)\    | 8 ( 0.7%)\         |          |         |
## |    |                                     | 24\. Failed To Stop At Proper \ | 7 ( 0.6%)\         |          |         |
## |    |                                     | 25\. Failed To Yield Right Of \ | 7 ( 0.6%)\         |          |         |
## |    |                                     | 26\. Turned Improperly - Wrong\ | 7 ( 0.6%)\         |          |         |
## |    |                                     | 27\. Under Influence - Drug\    | 6 ( 0.5%)\         |          |         |
## |    |                                     | 28\. Animal On Road - Domestic\ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 29\. Disregard Turn Marks At I\ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 30\. Failed To Heed Warning Si\ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 31\. Failed To Pass To Left Sa\ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 32\. Failed To Signal Or Gave \ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 33\. Fleeing Or Evading Police\ | 4 ( 0.3%)\         |          |         |
## |    |                                     | 34\. Wrong Side - Not Passing\  | 4 ( 0.3%)\         |          |         |
## |    |                                     | 35\. Wrong Way - One Way Road\  | 4 ( 0.3%)\         |          |         |
## |    |                                     | 36\. Cell/Mobile Device Use - \ | 3 ( 0.3%)\         |          |         |
## |    |                                     | 37\. Failed To Yield Right Of \ | 3 ( 0.3%)\         |          |         |
## |    |                                     | 38\. Improper Start From Parke\ | 3 ( 0.3%)\         |          |         |
## |    |                                     | 39\. Animal On Road - Wild\     | 2 ( 0.2%)\         |          |         |
## |    |                                     | 40\. Cell/Mobile Device Use - \ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 41\. Disabled In Traffic Lane\  | 2 ( 0.2%)\         |          |         |
## |    |                                     | 42\. Disregard Warning Sign At\ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 43\. Failed To Pass To Right S\ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 44\. Failed To Slow Or Move Ov\ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 45\. Failed To Yield Right Of \ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 46\. Ill (Explain In Narrative\ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 47\. Passed In No Passing Lane\ | 2 ( 0.2%)\         |          |         |
## |    |                                     | 48\. Road Rage\                 | 2 ( 0.2%)\         |          |         |
## |    |                                     | 49\. Cell/Mobile Device Use - \ | 1 ( 0.1%)\         |          |         |
## |    |                                     | 50\. Drove On Improved Shoulde\ | 1 ( 0.1%)\         |          |         |
## |    |                                     | 51\. Failed To Give Half Of Ro\ | 1 ( 0.1%)\         |          |         |
## |    |                                     | 52\. Fire In Vehicle\           | 1 ( 0.1%)\         |          |         |
## |    |                                     | 53\. Load Not Secured\          | 1 ( 0.1%)\         |          |         |
## |    |                                     | 54\. Parked Without Lights\     | 1 ( 0.1%)\         |          |         |
## |    |                                     | 55\. Passed On Right Shoulder\  | 1 ( 0.1%)\         |          |         |
## |    |                                     | 56\. Pedestrian Failed To Yiel\ | 1 ( 0.1%)\         |          |         |
## |    |                                     | 57\. Turned Improperly - Cut C\ | 1 ( 0.1%)\         |          |         |
## |    |                                     | 58\. Wrong Side - Approach Or   | 1 ( 0.1%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 35 | Prsn_Type_ID\                       | 1\. Driver\                     | 23769 (99.0%)\     | 24013\   | 1460\   |
## |    | [factor]                            | 2\. Passenger/Occupant\         | 120 ( 0.5%)\       | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Unknown\                    | 77 ( 0.3%)\        |          |         |
## |    |                                     | 4\. Driver Of Motorcycle Type   | 47 ( 0.2%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 36 | Prsn_Injry_Sev_ID\                  | 1\. Not Injured\                | 19915 (82.9%)\     | 24013\   | 1460\   |
## |    | [factor]                            | 2\. Possible Injury\            | 2007 ( 8.4%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Non-Incapacitating Injury\  | 1209 ( 5.0%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 712 ( 3.0%)\       |          |         |
## |    |                                     | 5\. Incapacitating Injury\      | 151 ( 0.6%)\       |          |         |
## |    |                                     | 6\. Killed                      | 19 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 37 | Prsn_Age\                           | 1\. 38\                         | 693 (3.0%)\        | 23429\   | 2044\   |
## |    | [factor]                            | 2\. 34\                         | 690 (2.9%)\        | (92.0%)  | (8.0%)  |
## |    |                                     | 3\. 31\                         | 666 (2.8%)\        |          |         |
## |    |                                     | 4\. 37\                         | 664 (2.8%)\        |          |         |
## |    |                                     | 5\. 32\                         | 658 (2.8%)\        |          |         |
## |    |                                     | 6\. 36\                         | 656 (2.8%)\        |          |         |
## |    |                                     | 7\. 39\                         | 652 (2.8%)\        |          |         |
## |    |                                     | 8\. 33\                         | 634 (2.7%)\        |          |         |
## |    |                                     | 9\. 35\                         | 633 (2.7%)\        |          |         |
## |    |                                     | 10\. 27\                        | 622 (2.7%)\        |          |         |
## |    |                                     | 11\. 40\                        | 611 (2.6%)\        |          |         |
## |    |                                     | 12\. 42\                        | 607 (2.6%)\        |          |         |
## |    |                                     | 13\. 41\                        | 600 (2.6%)\        |          |         |
## |    |                                     | 14\. 43\                        | 585 (2.5%)\        |          |         |
## |    |                                     | 15\. 29\                        | 577 (2.5%)\        |          |         |
## |    |                                     | 16\. 30\                        | 577 (2.5%)\        |          |         |
## |    |                                     | 17\. 45\                        | 548 (2.3%)\        |          |         |
## |    |                                     | 18\. 28\                        | 546 (2.3%)\        |          |         |
## |    |                                     | 19\. 46\                        | 546 (2.3%)\        |          |         |
## |    |                                     | 20\. 44\                        | 540 (2.3%)\        |          |         |
## |    |                                     | 21\. 25\                        | 538 (2.3%)\        |          |         |
## |    |                                     | 22\. 26\                        | 532 (2.3%)\        |          |         |
## |    |                                     | 23\. 48\                        | 504 (2.2%)\        |          |         |
## |    |                                     | 24\. 47\                        | 479 (2.0%)\        |          |         |
## |    |                                     | 25\. 24\                        | 445 (1.9%)\        |          |         |
## |    |                                     | 26\. 23\                        | 444 (1.9%)\        |          |         |
## |    |                                     | 27\. 50\                        | 423 (1.8%)\        |          |         |
## |    |                                     | 28\. 51\                        | 411 (1.8%)\        |          |         |
## |    |                                     | 29\. 49\                        | 407 (1.7%)\        |          |         |
## |    |                                     | 30\. 22\                        | 365 (1.6%)\        |          |         |
## |    |                                     | 31\. 53\                        | 361 (1.5%)\        |          |         |
## |    |                                     | 32\. 54\                        | 345 (1.5%)\        |          |         |
## |    |                                     | 33\. 21\                        | 344 (1.5%)\        |          |         |
## |    |                                     | 34\. 18\                        | 338 (1.4%)\        |          |         |
## |    |                                     | 35\. 17\                        | 335 (1.4%)\        |          |         |
## |    |                                     | 36\. 52\                        | 332 (1.4%)\        |          |         |
## |    |                                     | 37\. 20\                        | 321 (1.4%)\        |          |         |
## |    |                                     | 38\. 19\                        | 312 (1.3%)\        |          |         |
## |    |                                     | 39\. 56\                        | 276 (1.2%)\        |          |         |
## |    |                                     | 40\. 55\                        | 269 (1.1%)\        |          |         |
## |    |                                     | 41\. 57\                        | 264 (1.1%)\        |          |         |
## |    |                                     | 42\. 16\                        | 261 (1.1%)\        |          |         |
## |    |                                     | 43\. 58\                        | 237 (1.0%)\        |          |         |
## |    |                                     | 44\. 59\                        | 221 (0.9%)\        |          |         |
## |    |                                     | 45\. 60\                        | 194 (0.8%)\        |          |         |
## |    |                                     | 46\. 63\                        | 173 (0.7%)\        |          |         |
## |    |                                     | 47\. 62\                        | 171 (0.7%)\        |          |         |
## |    |                                     | 48\. 61\                        | 166 (0.7%)\        |          |         |
## |    |                                     | 49\. 64\                        | 149 (0.6%)\        |          |         |
## |    |                                     | 50\. 66\                        | 139 (0.6%)\        |          |         |
## |    |                                     | 51\. 65\                        | 138 (0.6%)\        |          |         |
## |    |                                     | 52\. 68\                        | 126 (0.5%)\        |          |         |
## |    |                                     | 53\. 67\                        | 108 (0.5%)\        |          |         |
## |    |                                     | 54\. 71\                        | 105 (0.4%)\        |          |         |
## |    |                                     | 55\. 69\                        | 99 (0.4%)\         |          |         |
## |    |                                     | 56\. 70\                        | 97 (0.4%)\         |          |         |
## |    |                                     | 57\. 72\                        | 88 (0.4%)\         |          |         |
## |    |                                     | 58\. 73\                        | 81 (0.3%)\         |          |         |
## |    |                                     | 59\. 75\                        | 73 (0.3%)\         |          |         |
## |    |                                     | 60\. 74\                        | 62 (0.3%)\         |          |         |
## |    |                                     | 61\. 76\                        | 62 (0.3%)\         |          |         |
## |    |                                     | 62\. 78\                        | 45 (0.2%)\         |          |         |
## |    |                                     | 63\. 79\                        | 39 (0.2%)\         |          |         |
## |    |                                     | 64\. 77\                        | 38 (0.2%)\         |          |         |
## |    |                                     | 65\. 82\                        | 34 (0.1%)\         |          |         |
## |    |                                     | 66\. 80\                        | 25 (0.1%)\         |          |         |
## |    |                                     | 67\. 15\                        | 22 (0.1%)\         |          |         |
## |    |                                     | 68\. 84\                        | 21 (0.1%)\         |          |         |
## |    |                                     | 69\. 81\                        | 20 (0.1%)\         |          |         |
## |    |                                     | 70\. 83\                        | 20 (0.1%)\         |          |         |
## |    |                                     | 71\. 85\                        | 13 (0.1%)\         |          |         |
## |    |                                     | 72\. 86\                        | 12 (0.1%)\         |          |         |
## |    |                                     | 73\. 89\                        | 10 (0.0%)\         |          |         |
## |    |                                     | 74\. 14\                        | 9 (0.0%)\          |          |         |
## |    |                                     | 75\. 87\                        | 8 (0.0%)\          |          |         |
## |    |                                     | 76\. 88\                        | 5 (0.0%)\          |          |         |
## |    |                                     | 77\. 13\                        | 2 (0.0%)\          |          |         |
## |    |                                     | 78\. 92\                        | 2 (0.0%)\          |          |         |
## |    |                                     | 79\. 1\                         | 1 (0.0%)\          |          |         |
## |    |                                     | 80\. 4\                         | 1 (0.0%)\          |          |         |
## |    |                                     | 81\. 90\                        | 1 (0.0%)\          |          |         |
## |    |                                     | 82\. 96                         | 1 (0.0%)           |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 38 | Prsn_Ethnicity_ID\                  | 1\. White\                      | 10500 (44.0%)\     | 23886\   | 1587\   |
## |    | [factor]                            | 2\. Asian\                      | 5312 (22.2%)\      | (93.8%)  | (6.2%)  |
## |    |                                     | 3\. Hispanic\                   | 3445 (14.4%)\      |          |         |
## |    |                                     | 4\. Black\                      | 3098 (13.0%)\      |          |         |
## |    |                                     | 5\. Unknown\                    | 577 ( 2.4%)\       |          |         |
## |    |                                     | 6\. Other\                      | 566 ( 2.4%)\       |          |         |
## |    |                                     | 7\. Amer. Indian/Alaskan Nati   | 388 ( 1.6%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 39 | Prsn_Gndr_ID\                       | 1\. Male\                       | 14612 (60.9%)\     | 24013\   | 1460\   |
## |    | [factor]                            | 2\. Female\                     | 9027 (37.6%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Unknown                     | 374 ( 1.6%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 40 | Prsn_Ejct_ID\                       | 1\. No\                         | 23240 (96.7%)\     | 24024\   | 1449\   |
## |    | [factor]                            | 2\. Unknown\                    | 367 ( 1.5%)\       | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Not Applicable\             | 341 ( 1.4%)\       |          |         |
## |    |                                     | 4\. Yes\                        | 73 ( 0.3%)\        |          |         |
## |    |                                     | 5\. Yes, Partial                | 3 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 41 | Prsn_Rest_ID\                       | 1\. Shoulder & Lap Belt\        | 22071 (91.9%)\     | 24024\   | 1449\   |
## |    | [factor]                            | 2\. Unknown\                    | 1484 ( 6.2%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Not Applicable\             | 197 ( 0.8%)\       |          |         |
## |    |                                     | 4\. Shoulder Belt Only\         | 131 ( 0.5%)\       |          |         |
## |    |                                     | 5\. None\                       | 119 ( 0.5%)\       |          |         |
## |    |                                     | 6\. Lap Belt Only\              | 10 ( 0.0%)\        |          |         |
## |    |                                     | 7\. Other (Explain In Narrati\  | 8 ( 0.0%)\         |          |         |
## |    |                                     | 8\. Child Seat, Facing Forwar\  | 2 ( 0.0%)\         |          |         |
## |    |                                     | 9\. Child Seat, Facing Rear\    | 1 ( 0.0%)\         |          |         |
## |    |                                     | 10\. Child Seat, Unknown        | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 42 | Prsn_Airbag_ID\                     | 1\. Not Deployed\               | 18164 (75.6%)\     | 24024\   | 1449\   |
## |    | [factor]                            | 2\. Deployed, Multiple\         | 2851 (11.9%)\      | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Deployed, Front\            | 1613 ( 6.7%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 619 ( 2.6%)\       |          |         |
## |    |                                     | 5\. Deployed, Side\             | 559 ( 2.3%)\       |          |         |
## |    |                                     | 6\. Not Applicable\             | 214 ( 0.9%)\       |          |         |
## |    |                                     | 7\. Deployed, Rear              | 4 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 43 | Prsn_Helmet_ID\                     | 1\. Not Applicable\             | 23956 (99.7%)\     | 24024\   | 1449\   |
## |    | [factor]                            | 2\. Not Worn\                   | 28 ( 0.1%)\        | (94.3%)  | (5.7%)  |
## |    |                                     | 3\. Worn, Damaged\              | 14 ( 0.1%)\        |          |         |
## |    |                                     | 4\. Worn, Not Damaged\          | 14 ( 0.1%)\        |          |         |
## |    |                                     | 5\. Worn, Unk Damage\           | 9 ( 0.0%)\         |          |         |
## |    |                                     | 6\. Unknown If Worn             | 3 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 44 | Drvr_Lic_Type_ID\                   | 1\. Driver License\             | 22767 (95.5%)\     | 23844\   | 1629\   |
## |    | [factor]                            | 2\. Unknown\                    | 504 ( 2.1%)\       | (93.6%)  | (6.4%)  |
## |    |                                     | 3\. Unlicensed\                 | 204 ( 0.9%)\       |          |         |
## |    |                                     | 4\. Commercial Driver Lic.\     | 170 ( 0.7%)\       |          |         |
## |    |                                     | 5\. Id Card\                    | 149 ( 0.6%)\       |          |         |
## |    |                                     | 6\. Other\                      | 45 ( 0.2%)\        |          |         |
## |    |                                     | 7\. Occupational                | 5 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 45 | E_Scooter_ID\                       | 1\. Not Applicable\             | 20554 (80.7%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. Data Not Available At Dat   | 4919 (19.3%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 46 | IsElectric\                         | 1\. TRUE                        | 25473 (100.0%)     | 25473\   | 0\      |
## |    | [factor]                            |                                 |                    | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 47 | IsHybrid\                           | 1\. FALSE\                      | 22791 (89.5%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. TRUE                        | 2682 (10.5%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 48 | HasAutomaticBrakingSystem\          | 1\. TRUE\                       | 22679 (89.0%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. FALSE                       | 2794 (11.0%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 49 | HasAutomaticEmergencyBrakingSystem\ | 1\. FALSE\                      | 23796 (93.4%)\     | 25473\   | 0\      |
## |    | [factor]                            | 2\. TRUE                        | 1677 ( 6.6%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+

Comparison

dat3a= dat3[, c("Crash_Speed_Limit", "Wthr_Cond_ID","Light_Cond_ID", "Road_Type_ID","Road_Algn_ID",
                 "Traffic_Cntl_ID","Harm_Evnt_ID", "Intrsct_Relat_ID", "FHE_Collsn_ID", "Othr_Factr_ID" ,"Obj_Struck_ID", "Road_Relat_ID" ,  "Crash_Sev_ID","Pop_Group_ID", "Day_of_Week"  , "Rural_Urban_Type_ID", "Func_Sys_ID" , "Prsn_Type_ID", "Prsn_Ethnicity_ID" , "Prsn_Gndr_ID",  "Prsn_Rest_ID" )]
dat2= dat[, c("Crash_Speed_Limit", "Wthr_Cond_ID","Light_Cond_ID", "Road_Type_ID","Road_Algn_ID",
                 "Traffic_Cntl_ID","Harm_Evnt_ID", "Intrsct_Relat_ID", "FHE_Collsn_ID", "Othr_Factr_ID" ,"Obj_Struck_ID", "Road_Relat_ID" ,  "Crash_Sev_ID","Pop_Group_ID", "Day_of_Week"  , "Rural_Urban_Type_ID", "Func_Sys_ID" , "Prsn_Type_ID", "Prsn_Ethnicity_ID" , "Prsn_Gndr_ID",  "Prsn_Rest_ID" )]


# Step 1: Select character/factor variables to compare
vars_to_compare <- dat2 %>%
  select(where(~is.character(.x) || is.factor(.x))) %>%
  names()

get_count_and_percentage <- function(data, variable) {
  data %>%
    filter(!is.na(.data[[variable]]) & .data[[variable]] != "") %>%  # Exclude NA/blank
    count(Value = .data[[variable]]) %>%
    mutate(Percentage = 100 * n / sum(n)) %>%  # Use `n` before renaming
    rename(Count = n)
}

# Step 3: Loop through variables and compare
comparison_list <- lapply(vars_to_compare, function(var) {
  orig <- get_count_and_percentage(dat2, var) %>%
    rename(Orig_Count = Count, Orig_Perc = Percentage)
  
  sub <- get_count_and_percentage(dat3a, var) %>%
    rename(Sub_Count = Count, Sub_Perc = Percentage)
  
  merged <- full_join(orig, sub, by = "Value") %>%
    mutate(Variable = var) %>%
    replace_na(list(Orig_Count = 0, Sub_Count = 0, Orig_Perc = 0, Sub_Perc = 0)) %>%
    mutate(
      Orig_Perc = round(Orig_Perc, 3),
      Sub_Perc = round(Sub_Perc, 3),
      Diff = round(Sub_Perc - Orig_Perc, 3)
    ) %>%
    arrange(Sub_Perc)
})

# Step 4: Combine into one data frame
comparison_df <- bind_rows(comparison_list) %>%
  select(Variable, Value, Orig_Count, Sub_Count, Orig_Perc, Sub_Perc, Diff)

# Step 5: Visualize with colored difference
DT::datatable(comparison_df, options = list(pageLength = 25)) %>%
  DT::formatStyle(
    'Diff',
    color = DT::styleInterval(0, c('red', 'green'))  # red for negative, green for positive
  )