AEB 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$HasAutomaticEmergencyBrakingSystem)
## 
##   Error   FALSE    TRUE Unknown 
##     950 9011205   48838      73
dat3= subset(dat1b, HasAutomaticEmergencyBrakingSystem==TRUE)
dim(dat3)
## [1] 48838    63
write.csv(dat3, "AEBYes_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:** 48838 x 49  
## **Duplicates:** 1  
## 
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | No | Variable                            | Stats / Values                  | Freqs (% of Valid) | Valid    | Missing |
## +====+=====================================+=================================+====================+==========+=========+
## | 1  | UnitNbr_Pr\                         | 1\. 2\                          | 22038 (48.0%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. 1\                          | 19986 (43.5%)\     | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. 3\                          | 3185 ( 6.9%)\      |          |         |
## |    |                                     | 4\. 4\                          | 530 ( 1.2%)\       |          |         |
## |    |                                     | 5\. 5\                          | 137 ( 0.3%)\       |          |         |
## |    |                                     | 6\. 6\                          | 39 ( 0.1%)\        |          |         |
## |    |                                     | 7\. 7\                          | 10 ( 0.0%)\        |          |         |
## |    |                                     | 8\. 8\                          | 9 ( 0.0%)\         |          |         |
## |    |                                     | 9\. 9\                          | 4 ( 0.0%)\         |          |         |
## |    |                                     | 10\. 11\                        | 4 ( 0.0%)\         |          |         |
## |    |                                     | 11\. 12\                        | 2 ( 0.0%)\         |          |         |
## |    |                                     | 12\. 94                         | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 2  | Year\                               | 1\. 2024\                       | 14460 (29.6%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. 2023\                       | 9180 (18.8%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 2022\                       | 7169 (14.7%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 5551 (11.4%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 3747 ( 7.7%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 3614 ( 7.4%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 2849 ( 5.8%)\      |          |         |
## |    |                                     | 8\. 2017                        | 2268 ( 4.6%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 3  | Yr_Un\                              | 1\. 2024\                       | 14460 (29.6%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. 2023\                       | 9180 (18.8%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 2022\                       | 7169 (14.7%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 5551 (11.4%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 3747 ( 7.7%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 3614 ( 7.4%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 2849 ( 5.8%)\      |          |         |
## |    |                                     | 8\. 2017                        | 2268 ( 4.6%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 4  | Yr_Pr\                              | 1\. 2024\                       | 13618 (29.6%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. 2023\                       | 8635 (18.8%)\      | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. 2022\                       | 6717 (14.6%)\      |          |         |
## |    |                                     | 4\. 2021\                       | 5219 (11.4%)\      |          |         |
## |    |                                     | 5\. 2019\                       | 3552 ( 7.7%)\      |          |         |
## |    |                                     | 6\. 2020\                       | 3401 ( 7.4%)\      |          |         |
## |    |                                     | 7\. 2018\                       | 2655 ( 5.8%)\      |          |         |
## |    |                                     | 8\. 2017                        | 2148 ( 4.7%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 5  | Prsn_Nbr\                           | 1\. 1                           | 45945 (100.0%)     | 45945\   | 2893\   |
## |    | [factor]                            |                                 |                    | (94.1%)  | (5.9%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 6  | Crash_Speed_Limit\                  | 1\. 45\                         | 8451 (17.3%)\      | 48838\   | 0\      |
## |    | [factor]                            | 2\. 35\                         | 7196 (14.7%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 30\                         | 6310 (12.9%)\      |          |         |
## |    |                                     | 4\. 40\                         | 5970 (12.2%)\      |          |         |
## |    |                                     | 5\. 65\                         | 3718 ( 7.6%)\      |          |         |
## |    |                                     | 6\. 60\                         | 3108 ( 6.4%)\      |          |         |
## |    |                                     | 7\. 55\                         | 2790 ( 5.7%)\      |          |         |
## |    |                                     | 8\. -1\                         | 2729 ( 5.6%)\      |          |         |
## |    |                                     | 9\. 70\                         | 2273 ( 4.7%)\      |          |         |
## |    |                                     | 10\. 50\                        | 2253 ( 4.6%)\      |          |         |
## |    |                                     | 11\. 75\                        | 1068 ( 2.2%)\      |          |         |
## |    |                                     | 12\. 5\                         | 810 ( 1.7%)\       |          |         |
## |    |                                     | 13\. 10\                        | 608 ( 1.2%)\       |          |         |
## |    |                                     | 14\. 15\                        | 521 ( 1.1%)\       |          |         |
## |    |                                     | 15\. 20\                        | 484 ( 1.0%)\       |          |         |
## |    |                                     | 16\. 25\                        | 478 ( 1.0%)\       |          |         |
## |    |                                     | 17\. 80\                        | 65 ( 0.1%)\        |          |         |
## |    |                                     | 18\. 6\                         | 2 ( 0.0%)\         |          |         |
## |    |                                     | 19\. 85\                        | 2 ( 0.0%)\         |          |         |
## |    |                                     | 20\. 9\                         | 1 ( 0.0%)\         |          |         |
## |    |                                     | 21\. 39                         | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 7  | Wthr_Cond_ID\                       | 1\. Clear\                      | 38652 (79.1%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Cloudy\                     | 6230 (12.8%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Rain\                       | 3340 ( 6.8%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 298 ( 0.6%)\       |          |         |
## |    |                                     | 5\. Fog\                        | 128 ( 0.3%)\       |          |         |
## |    |                                     | 6\. Sleet/Hail\                 | 75 ( 0.2%)\        |          |         |
## |    |                                     | 7\. Snow\                       | 53 ( 0.1%)\        |          |         |
## |    |                                     | 8\. Other (Explain In Narrati\  | 40 ( 0.1%)\        |          |         |
## |    |                                     | 9\. Severe Crosswinds\          | 16 ( 0.0%)\        |          |         |
## |    |                                     | 10\. Blowing Sand/Snow          | 6 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 8  | Light_Cond_ID\                      | 1\. Daylight\                   | 35274 (72.2%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Dark, Lighted\              | 9059 (18.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Dark, Not Lighted\          | 2903 ( 5.9%)\      |          |         |
## |    |                                     | 4\. Dusk\                       | 530 ( 1.1%)\       |          |         |
## |    |                                     | 5\. Dark, Unknown Lighting\     | 446 ( 0.9%)\       |          |         |
## |    |                                     | 6\. Dawn\                       | 364 ( 0.7%)\       |          |         |
## |    |                                     | 7\. Unknown\                    | 225 ( 0.5%)\       |          |         |
## |    |                                     | 8\. Other (Explain In Narrati   | 37 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 9  | Entr_Road_ID\                       | 1\. Not Applicable\             | 27021 (55.3%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Four Entering Roads\        | 9400 (19.2%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Three Entering Roads - T\   | 7077 (14.5%)\      |          |         |
## |    |                                     | 4\. Other (Explain In Narrati\  | 4202 ( 8.6%)\      |          |         |
## |    |                                     | 5\. Three Entering Roads - Y\   | 685 ( 1.4%)\       |          |         |
## |    |                                     | 6\. Five Entering Roads\        | 187 ( 0.4%)\       |          |         |
## |    |                                     | 7\. Six Entering Roads\         | 136 ( 0.3%)\       |          |         |
## |    |                                     | 8\. Traffic Circle\             | 80 ( 0.2%)\        |          |         |
## |    |                                     | 9\. Cloverleaf                  | 50 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 10 | Road_Type_ID\                       | 1\. 2 Lane, 2 Way\              | 12693 (35.2%)\     | 36037\   | 12801\  |
## |    | [factor]                            | 2\. 4 Or More Lanes, Undivide\  | 12524 (34.8%)\     | (73.8%)  | (26.2%) |
## |    |                                     | 3\. 4 Or More Lanes, Divided    | 10820 (30.0%)      |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 11 | Road_Algn_ID\                       | 1\. Straight, Level\            | 41526 (85.0%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Straight, Grade\            | 3074 ( 6.3%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Curve, Level\               | 1766 ( 3.6%)\      |          |         |
## |    |                                     | 4\. Straight, Hillcrest\        | 830 ( 1.7%)\       |          |         |
## |    |                                     | 5\. Curve, Grade\               | 794 ( 1.6%)\       |          |         |
## |    |                                     | 6\. Other (Explain In Narrati\  | 566 ( 1.2%)\       |          |         |
## |    |                                     | 7\. Curve, Hillcrest\           | 149 ( 0.3%)\       |          |         |
## |    |                                     | 8\. Unknown                     | 133 ( 0.3%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 12 | Surf_Cond_ID\                       | 1\. Dry\                        | 43369 (88.8%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Wet\                        | 4730 ( 9.7%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Unknown\                    | 301 ( 0.6%)\       |          |         |
## |    |                                     | 4\. Standing Water\             | 166 ( 0.3%)\       |          |         |
## |    |                                     | 5\. Ice\                        | 151 ( 0.3%)\       |          |         |
## |    |                                     | 6\. Other (Explain In Narrati\  | 55 ( 0.1%)\        |          |         |
## |    |                                     | 7\. Sand, Mud, Dirt\            | 36 ( 0.1%)\        |          |         |
## |    |                                     | 8\. Snow\                       | 16 ( 0.0%)\        |          |         |
## |    |                                     | 9\. Slush                       | 14 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 13 | Traffic_Cntl_ID\                    | 1\. Marked Lanes\               | 21089 (43.2%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Signal Light\               | 9053 (18.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. None\                       | 8599 (17.6%)\      |          |         |
## |    |                                     | 4\. Stop Sign\                  | 4521 ( 9.3%)\      |          |         |
## |    |                                     | 5\. Center Stripe/Divider\      | 1938 ( 4.0%)\      |          |         |
## |    |                                     | 6\. Other (Explain In Narrati\  | 1596 ( 3.3%)\      |          |         |
## |    |                                     | 7\. Yield Sign\                 | 771 ( 1.6%)\       |          |         |
## |    |                                     | 8\. Signal Light With Red Lig\  | 276 ( 0.6%)\       |          |         |
## |    |                                     | 9\. No Passing Zone\            | 212 ( 0.4%)\       |          |         |
## |    |                                     | 10\. Officer\                   | 160 ( 0.3%)\       |          |         |
## |    |                                     | 11\. Flashing Red Light\        | 155 ( 0.3%)\       |          |         |
## |    |                                     | 12\. Inoperative (Explain In N\ | 136 ( 0.3%)\       |          |         |
## |    |                                     | 13\. Warning Sign\              | 102 ( 0.2%)\       |          |         |
## |    |                                     | 14\. Flashing Yellow Light\     | 91 ( 0.2%)\        |          |         |
## |    |                                     | 15\. Crosswalk\                 | 60 ( 0.1%)\        |          |         |
## |    |                                     | 16\. Flagman\                   | 34 ( 0.1%)\        |          |         |
## |    |                                     | 17\. Rr Gate/Signal\            | 25 ( 0.1%)\        |          |         |
## |    |                                     | 18\. Bike Lane                  | 20 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 14 | Harm_Evnt_ID\                       | 1\. Motor Vehicle In Transpor\  | 40116 (82.1%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Parked Car\                 | 3786 ( 7.8%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Fixed Object\               | 3642 ( 7.5%)\      |          |         |
## |    |                                     | 4\. Animal\                     | 314 ( 0.6%)\       |          |         |
## |    |                                     | 5\. Pedestrian\                 | 278 ( 0.6%)\       |          |         |
## |    |                                     | 6\. Other Object\               | 260 ( 0.5%)\       |          |         |
## |    |                                     | 7\. Overturned\                 | 185 ( 0.4%)\       |          |         |
## |    |                                     | 8\. Pedalcyclist\               | 167 ( 0.3%)\       |          |         |
## |    |                                     | 9\. Other Non Collision\        | 75 ( 0.2%)\        |          |         |
## |    |                                     | 10\. Rr Train                   | 15 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 15 | Intrsct_Relat_ID\                   | 1\. Non Intersection\           | 25375 (52.0%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Intersection\               | 11014 (22.6%)\     | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Intersection Related\       | 8183 (16.8%)\      |          |         |
## |    |                                     | 4\. Driveway Access             | 4266 ( 8.7%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 16 | FHE_Collsn_ID\                      | 1\. Same Direction - Both Goi\  | 8127 (16.6%)\      | 48838\   | 0\      |
## |    | [factor]                            | 2\. Same Direction - One Stra\  | 7062 (14.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Same Direction - Both Goi\  | 6472 (13.3%)\      |          |         |
## |    |                                     | 4\. Angle - Both Going Straig\  | 6013 (12.3%)\      |          |         |
## |    |                                     | 5\. One Motor Vehicle - Going\  | 5804 (11.9%)\      |          |         |
## |    |                                     | 6\. Opposite Direction - One \  | 3561 ( 7.3%)\      |          |         |
## |    |                                     | 7\. Angle - One Straight-One \  | 2293 ( 4.7%)\      |          |         |
## |    |                                     | 8\. Angle - One Straight-One \  | 1257 ( 2.6%)\      |          |         |
## |    |                                     | 9\. One Motor Vehicle - Backi\  | 1179 ( 2.4%)\      |          |         |
## |    |                                     | 10\. Same Direction - One Stra\ | 1120 ( 2.3%)\      |          |         |
## |    |                                     | 11\. One Motor Vehicle - Other\ | 843 ( 1.7%)\       |          |         |
## |    |                                     | 12\. Same Direction - One Stra\ | 741 ( 1.5%)\       |          |         |
## |    |                                     | 13\. Opposite Direction - Both\ | 566 ( 1.2%)\       |          |         |
## |    |                                     | 14\. One Motor Vehicle - Turni\ | 462 ( 0.9%)\       |          |         |
## |    |                                     | 15\. One Motor Vehicle - Turni\ | 434 ( 0.9%)\       |          |         |
## |    |                                     | 16\. Other - One Straight-One \ | 344 ( 0.7%)\       |          |         |
## |    |                                     | 17\. Same Direction - Both Lef\ | 324 ( 0.7%)\       |          |         |
## |    |                                     | 18\. Same Direction - Both Rig\ | 306 ( 0.6%)\       |          |         |
## |    |                                     | 19\. Opposite Direction - One \ | 254 ( 0.5%)\       |          |         |
## |    |                                     | 20\. Angle - One Straight-One \ | 218 ( 0.4%)\       |          |         |
## |    |                                     | 21\. Other\                     | 211 ( 0.4%)\       |          |         |
## |    |                                     | 22\. Opposite Direction - One \ | 208 ( 0.4%)\       |          |         |
## |    |                                     | 23\. Angle - One Left Turn-One\ | 170 ( 0.3%)\       |          |         |
## |    |                                     | 24\. Angle - One Right Turn-On\ | 145 ( 0.3%)\       |          |         |
## |    |                                     | 25\. Opposite Direction - One \ | 133 ( 0.3%)\       |          |         |
## |    |                                     | 26\. Other - Both Backing\      | 120 ( 0.2%)\       |          |         |
## |    |                                     | 27\. Angle - Both Left Turn\    | 74 ( 0.2%)\        |          |         |
## |    |                                     | 28\. Other - One Entering Or L\ | 66 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Angle - One Straight-One \ | 62 ( 0.1%)\        |          |         |
## |    |                                     | 30\. Angle - One Right Turn-On\ | 59 ( 0.1%)\        |          |         |
## |    |                                     | 31\. Opposite Direction - One \ | 54 ( 0.1%)\        |          |         |
## |    |                                     | 32\. Same Direction - One Righ\ | 49 ( 0.1%)\        |          |         |
## |    |                                     | 33\. Opposite Direction - Both\ | 36 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Opposite Direction - One \ | 19 ( 0.0%)\        |          |         |
## |    |                                     | 35\. Other - Both Entering Or \ | 19 ( 0.0%)\        |          |         |
## |    |                                     | 36\. Opposite Direction - One \ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 37\. Same Direction - One Left\ | 8 ( 0.0%)\         |          |         |
## |    |                                     | 38\. Same Direction - One Righ\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 39\. Other - One Left Turn-One\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 40\. Angle - Both Right Turn\   | 3 ( 0.0%)\         |          |         |
## |    |                                     | 41\. Other - One Right Turn-On  | 3 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 17 | Obj_Struck_ID\                      | 1\. Not Applicable\             | 42766 (87.6%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Hit Median Barrier (Concr\  | 876 ( 1.8%)\       | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Overturned\                 | 555 ( 1.1%)\       |          |         |
## |    |                                     | 4\. Hit Fence\                  | 450 ( 0.9%)\       |          |         |
## |    |                                     | 5\. Hit Tree, Shrub, Landscap\  | 431 ( 0.9%)\       |          |         |
## |    |                                     | 6\. Hit Guardrail\              | 382 ( 0.8%)\       |          |         |
## |    |                                     | 7\. Hit Other Fixed Object\     | 381 ( 0.8%)\       |          |         |
## |    |                                     | 8\. Hit Concrete Traffic Barr\  | 356 ( 0.7%)\       |          |         |
## |    |                                     | 9\. Hit Highway Sign\           | 321 ( 0.7%)\       |          |         |
## |    |                                     | 10\. Hit Curb\                  | 282 ( 0.6%)\       |          |         |
## |    |                                     | 11\. Hit Luminaire Pole\        | 272 ( 0.6%)\       |          |         |
## |    |                                     | 12\. Other\                     | 233 ( 0.5%)\       |          |         |
## |    |                                     | 13\. Hit Retaining Wall\        | 227 ( 0.5%)\       |          |         |
## |    |                                     | 14\. Hit House, Building, Or B\ | 200 ( 0.4%)\       |          |         |
## |    |                                     | 15\. Hit Utility Pole\          | 166 ( 0.3%)\       |          |         |
## |    |                                     | 16\. Hit Mailbox\               | 127 ( 0.3%)\       |          |         |
## |    |                                     | 17\. Ditch\                     | 124 ( 0.3%)\       |          |         |
## |    |                                     | 18\. Hit Traffic Signal Pole O\ | 101 ( 0.2%)\       |          |         |
## |    |                                     | 19\. Hit Attenuation Device\    | 89 ( 0.2%)\        |          |         |
## |    |                                     | 20\. Fire Hydrant\              | 58 ( 0.1%)\        |          |         |
## |    |                                     | 21\. Hit Culvert-Headwall\      | 56 ( 0.1%)\        |          |         |
## |    |                                     | 22\. Hit Commercial Sign\       | 45 ( 0.1%)\        |          |         |
## |    |                                     | 23\. Hit Work Zone Barricade, \ | 44 ( 0.1%)\        |          |         |
## |    |                                     | 24\. Hit Side Of Bridge (Bridg\ | 37 ( 0.1%)\        |          |         |
## |    |                                     | 25\. Jack-Knifed\               | 34 ( 0.1%)\        |          |         |
## |    |                                     | 26\. Embankment\                | 30 ( 0.1%)\        |          |         |
## |    |                                     | 27\. Hit Object From Another V\ | 28 ( 0.1%)\        |          |         |
## |    |                                     | 28\. Hit Overhead Signal Light\ | 27 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Hit Pier Or Support At Un\ | 26 ( 0.1%)\        |          |         |
## |    |                                     | 30\. Hit Previously Wrecked\    | 21 ( 0.0%)\        |          |         |
## |    |                                     | 31\. Hit Hole In Road\          | 16 ( 0.0%)\        |          |         |
## |    |                                     | 32\. Hit Delineator Or Marker \ | 15 ( 0.0%)\        |          |         |
## |    |                                     | 33\. Hit Train Moving Forward\  | 14 ( 0.0%)\        |          |         |
## |    |                                     | 34\. Hit Fallen Trees Or Debri\ | 12 ( 0.0%)\        |          |         |
## |    |                                     | 35\. Hit Other Machinery\       | 8 ( 0.0%)\         |          |         |
## |    |                                     | 36\. Hit Bus Stop Structure (B\ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 37\. Hit Railroad Crossing Gat\ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 38\. Hit Top Of Underpass Or T\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 39\. Person Fell Or Jumped Fro\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 40\. Hit Work Zone Machinery O\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 41\. Hit Train Standing Still\  | 2 ( 0.0%)\         |          |         |
## |    |                                     | 42\. Hit Hov Lane Gate\         | 1 ( 0.0%)\         |          |         |
## |    |                                     | 43\. Hit Railroad Signal Pole \ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 44\. Hit Toll Booth             | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 18 | Othr_Factr_ID\                      | 1\. Not Applicable·\            | 19591 (40.1%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Attention Diverted From D\  | 4632 ( 9.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Vehicle Changing Lanes·\    | 4328 ( 8.9%)\      |          |         |
## |    |                                     | 4\. Slowing/Stopping-For Traf\  | 4060 ( 8.3%)\      |          |         |
## |    |                                     | 5\. Slowing/Stopping - For Of\  | 3672 ( 7.5%)\      |          |         |
## |    |                                     | 6\. One Vehicle Leaving Drive\  | 2861 ( 5.9%)\      |          |         |
## |    |                                     | 7\. Construction - Within Pos\  | 1988 ( 4.1%)\      |          |         |
## |    |                                     | 8\. One Vehicle Entering Driv\  | 1360 ( 2.8%)\      |          |         |
## |    |                                     | 9\. One Vehicle Backward From\  | 1032 ( 2.1%)\      |          |         |
## |    |                                     | 10\. Slowing/Stopping-Reason N\ | 770 ( 1.6%)\       |          |         |
## |    |                                     | 11\. Lost Control Or Skidded (\ | 712 ( 1.5%)\       |          |         |
## |    |                                     | 12\. Slowing/Stopping-To Make \ | 551 ( 1.1%)\       |          |         |
## |    |                                     | 13\. Slowing/Stopping-To Make \ | 414 ( 0.8%)\       |          |         |
## |    |                                     | 14\. Vehicle Passing Or Attemp\ | 319 ( 0.7%)\       |          |         |
## |    |                                     | 15\. Construction-Within Poste\ | 315 ( 0.6%)\       |          |         |
## |    |                                     | 16\. Swerved Or Veered-Reason \ | 314 ( 0.6%)\       |          |         |
## |    |                                     | 17\. Swerved Or Veered-Avoidin\ | 271 ( 0.6%)\       |          |         |
## |    |                                     | 18\. One Vehicle Forward From \ | 211 ( 0.4%)\       |          |         |
## |    |                                     | 19\. One Vehicle Parked Improp\ | 147 ( 0.3%)\       |          |         |
## |    |                                     | 20\. Vehicle Passing Or Attemp\ | 135 ( 0.3%)\       |          |         |
## |    |                                     | 21\. School Bus Related Crash·\ | 134 ( 0.3%)\       |          |         |
## |    |                                     | 22\. Swerved Or Veered-Avoidin\ | 122 ( 0.2%)\       |          |         |
## |    |                                     | 23\. Swerved Or Veered-Avoidin\ | 96 ( 0.2%)\        |          |         |
## |    |                                     | 24\. Swerved Or Veered-Avoidin\ | 96 ( 0.2%)\        |          |         |
## |    |                                     | 25\. Slowing/Stopping-To Avoid\ | 82 ( 0.2%)\        |          |         |
## |    |                                     | 26\. Vision Obstructed By Head\ | 79 ( 0.2%)\        |          |         |
## |    |                                     | 27\. Open Door Or Object Proje\ | 64 ( 0.1%)\        |          |         |
## |    |                                     | 28\. Slowing/Stopping-For Pede\ | 51 ( 0.1%)\        |          |         |
## |    |                                     | 29\. Construction-In Other Con\ | 50 ( 0.1%)\        |          |         |
## |    |                                     | 30\. Swerved Or Veered - Avoid\ | 49 ( 0.1%)\        |          |         |
## |    |                                     | 31\. Foot Slipped Off Brake Or\ | 48 ( 0.1%)\        |          |         |
## |    |                                     | 32\. Slowing/Stopping-For Obje\ | 42 ( 0.1%)\        |          |         |
## |    |                                     | 33\. Swerved Or Veered-Avoidin\ | 35 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Vision Obstructed By Othe\ | 32 ( 0.1%)\        |          |         |
## |    |                                     | 35\. Vision Obstructed By Movi\ | 28 ( 0.1%)\        |          |         |
## |    |                                     | 36\. Slowing/Stopping-For Vehi\ | 27 ( 0.1%)\        |          |         |
## |    |                                     | 37\. Vision Obstructed By Stan\ | 21 ( 0.0%)\        |          |         |
## |    |                                     | 38\. Slowing/Stopping-For Anim\ | 20 ( 0.0%)\        |          |         |
## |    |                                     | 39\. Slowing/Stopping-For Surf\ | 19 ( 0.0%)\        |          |         |
## |    |                                     | 40\. Swerved Or Veered-Avoidin\ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 41\. Slowing/Stopping-For Vehi\ | 9 ( 0.0%)\         |          |         |
## |    |                                     | 42\. Swerved Or Veered-For Sur\ | 8 ( 0.0%)\         |          |         |
## |    |                                     | 43\. Gusty Winds·\              | 7 ( 0.0%)\         |          |         |
## |    |                                     | 44\. Passenger Interfered With\ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 45\. Construction - In Other C\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 46\. Vision Obstructed By Tree\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 47\. Swerved Or Veered-Avoidin\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 48\. Vision Obstructed By Hill\ | 4 ( 0.0%)\         |          |         |
## |    |                                     | 49\. Crash Occurred On A Beach  | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 19 | Road_Part_Adj_ID\                   | 1\. Main/Proper Lane\           | 38401 (78.6%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Service/Frontage Road\      | 5148 (10.5%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Other (Explain In Narrati\  | 4296 ( 8.8%)\      |          |         |
## |    |                                     | 4\. Exit/Off Ramp\              | 434 ( 0.9%)\       |          |         |
## |    |                                     | 5\. Entrance/On Ramp\           | 387 ( 0.8%)\       |          |         |
## |    |                                     | 6\. Connector/Flyover           | 172 ( 0.4%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 20 | Road_Cls_ID\                        | 1\. City Street\                | 18015 (36.9%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Us & State Highways\        | 10335 (21.2%)\     | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Interstate\                 | 8515 (17.4%)\      |          |         |
## |    |                                     | 4\. Non Trafficway\             | 4281 ( 8.8%)\      |          |         |
## |    |                                     | 5\. Farm To Market\             | 3538 ( 7.2%)\      |          |         |
## |    |                                     | 6\. County Road\                | 2900 ( 5.9%)\      |          |         |
## |    |                                     | 7\. Tollway\                    | 1233 ( 2.5%)\      |          |         |
## |    |                                     | 8\. Other Roads\                | 20 ( 0.0%)\        |          |         |
## |    |                                     | 9\. Toll Bridges                | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 21 | Road_Relat_ID\                      | 1\. On Roadway\                 | 40716 (83.4%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Not Applicable\             | 4278 ( 8.8%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Off Roadway\                | 2929 ( 6.0%)\      |          |         |
## |    |                                     | 4\. Median\                     | 804 ( 1.6%)\       |          |         |
## |    |                                     | 5\. Shoulder                    | 111 ( 0.2%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 22 | Crash_Sev_ID\                       | 1\. Not Injured\                | 33768 (69.1%)\     | 48837\   | 1\      |
## |    | [factor]                            | 2\. Possible Injury\            | 6958 (14.2%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Non-Incapacitating\         | 4872 (10.0%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 2227 ( 4.6%)\      |          |         |
## |    |                                     | 5\. Incapacitating Injury\      | 834 ( 1.7%)\       |          |         |
## |    |                                     | 6\. Killed                      | 178 ( 0.4%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 23 | Pop_Group_ID\                       | 1\. 250,000 Pop And Over\       | 20678 (42.3%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Rural\                      | 9439 (19.3%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 100,000 - 249,999 Pop\      | 6270 (12.8%)\      |          |         |
## |    |                                     | 4\. 50,000 - 99,999 Pop\        | 4004 ( 8.2%)\      |          |         |
## |    |                                     | 5\. 10,000 - 24,999 Pop\        | 2837 ( 5.8%)\      |          |         |
## |    |                                     | 6\. 25,000 - 49,999 Pop\        | 2477 ( 5.1%)\      |          |         |
## |    |                                     | 7\. 5,000 - 9,999 Pop\          | 1415 ( 2.9%)\      |          |         |
## |    |                                     | 8\. 2,500 - 4,999 Pop\          | 1013 ( 2.1%)\      |          |         |
## |    |                                     | 9\. Town Under 2,499 Pop        | 705 ( 1.4%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 24 | Day_of_Week\                        | 1\. FRI\                        | 8124 (16.6%)\      | 48838\   | 0\      |
## |    | [factor]                            | 2\. THU\                        | 7459 (15.3%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. WED\                        | 7307 (15.0%)\      |          |         |
## |    |                                     | 4\. TUE\                        | 7184 (14.7%)\      |          |         |
## |    |                                     | 5\. SAT\                        | 6845 (14.0%)\      |          |         |
## |    |                                     | 6\. MON\                        | 6783 (13.9%)\      |          |         |
## |    |                                     | 7\. SUN                         | 5136 (10.5%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 25 | Rural_Urban_Type_ID\                | 1\. Urbanized (200,000+)\       | 16562 (72.3%)\     | 22909\   | 25929\  |
## |    | [factor]                            | 2\. Rural (<5000)\              | 2695 (11.8%)\      | (46.9%)  | (53.1%) |
## |    |                                     | 3\. Large Urban (50,000-199,9\  | 2194 ( 9.6%)\      |          |         |
## |    |                                     | 4\. Small Urban (5000-49,999)   | 1458 ( 6.4%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 26 | Func_Sys_ID\                        | 1\. Rural Interstate\           | 8450 (71.3%)\      | 11850\   | 36988\  |
## |    | [factor]                            | 2\. Rural Prin Arterial\        | 3350 (28.3%)\      | (24.3%)  | (75.7%) |
## |    |                                     | 3\. Rural Minor Arterial\       | 39 ( 0.3%)\        |          |         |
## |    |                                     | 4\. Rural Major Coll            | 11 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 27 | Veh_Mod_Year\                       | 1\. 2019\                       | 4973 (10.5%)\      | 47401\   | 1437\   |
## |    | [factor]                            | 2\. 2017\                       | 4567 ( 9.6%)\      | (97.1%)  | (2.9%)  |
## |    |                                     | 3\. 2020\                       | 4494 ( 9.5%)\      |          |         |
## |    |                                     | 4\. 2018\                       | 4453 ( 9.4%)\      |          |         |
## |    |                                     | 5\. 2021\                       | 4426 ( 9.3%)\      |          |         |
## |    |                                     | 6\. 2022\                       | 4352 ( 9.2%)\      |          |         |
## |    |                                     | 7\. 2016\                       | 4202 ( 8.9%)\      |          |         |
## |    |                                     | 8\. 2023\                       | 3898 ( 8.2%)\      |          |         |
## |    |                                     | 9\. 2024\                       | 3815 ( 8.0%)\      |          |         |
## |    |                                     | 10\. 2015\                      | 3133 ( 6.6%)\      |          |         |
## |    |                                     | 11\. 2025\                      | 1781 ( 3.8%)\      |          |         |
## |    |                                     | 12\. 2014\                      | 1631 ( 3.4%)\      |          |         |
## |    |                                     | 13\. 2013\                      | 857 ( 1.8%)\       |          |         |
## |    |                                     | 14\. 2012\                      | 535 ( 1.1%)\       |          |         |
## |    |                                     | 15\. 2010\                      | 146 ( 0.3%)\       |          |         |
## |    |                                     | 16\. 2011\                      | 95 ( 0.2%)\        |          |         |
## |    |                                     | 17\. 2009\                      | 35 ( 0.1%)\        |          |         |
## |    |                                     | 18\. 2008\                      | 7 ( 0.0%)\         |          |         |
## |    |                                     | 19\. 2026                       | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 28 | Veh_Color_ID\                       | 1\. White\                      | 13909 (28.6%)\     | 48559\   | 279\    |
## |    | [factor]                            | 2\. Black\                      | 13308 (27.4%)\     | (99.4%)  | (0.6%)  |
## |    |                                     | 3\. Gray\                       | 7010 (14.4%)\      |          |         |
## |    |                                     | 4\. Silver\                     | 4473 ( 9.2%)\      |          |         |
## |    |                                     | 5\. Blue\                       | 3903 ( 8.0%)\      |          |         |
## |    |                                     | 6\. Red\                        | 2847 ( 5.9%)\      |          |         |
## |    |                                     | 7\. Unknown\                    | 538 ( 1.1%)\       |          |         |
## |    |                                     | 8\. Green\                      | 491 ( 1.0%)\       |          |         |
## |    |                                     | 9\. Maroon\                     | 465 ( 1.0%)\       |          |         |
## |    |                                     | 10\. Gold\                      | 282 ( 0.6%)\       |          |         |
## |    |                                     | 11\. Brown\                     | 279 ( 0.6%)\       |          |         |
## |    |                                     | 12\. Beige\                     | 215 ( 0.4%)\       |          |         |
## |    |                                     | 13\. Tan\                       | 213 ( 0.4%)\       |          |         |
## |    |                                     | 14\. Orange\                    | 197 ( 0.4%)\       |          |         |
## |    |                                     | 15\. Yellow\                    | 122 ( 0.3%)\       |          |         |
## |    |                                     | 16\. Multicolored\              | 120 ( 0.2%)\       |          |         |
## |    |                                     | 17\. Purple\                    | 60 ( 0.1%)\        |          |         |
## |    |                                     | 18\. Turquoise(Blue)\           | 41 ( 0.1%)\        |          |         |
## |    |                                     | 19\. Bronze\                    | 36 ( 0.1%)\        |          |         |
## |    |                                     | 20\. Pink\                      | 17 ( 0.0%)\        |          |         |
## |    |                                     | 21\. Teal(Green)\               | 13 ( 0.0%)\        |          |         |
## |    |                                     | 22\. Other (Explain In Narrati\ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 23\. Copper\                    | 7 ( 0.0%)\         |          |         |
## |    |                                     | 24\. Camouflage                 | 2 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 29 | Veh_Make_ID\                        | 1\. Bmw\                        | 6541 (13.4%)\      | 48838\   | 0\      |
## |    | [factor]                            | 2\. Mercedes-Benz\              | 5412 (11.1%)\      | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Lexus\                      | 5179 (10.6%)\      |          |         |
## |    |                                     | 4\. Audi\                       | 4073 ( 8.3%)\      |          |         |
## |    |                                     | 5\. Volvo\                      | 2610 ( 5.3%)\      |          |         |
## |    |                                     | 6\. Toyota\                     | 1911 ( 3.9%)\      |          |         |
## |    |                                     | 7\. Cadillac\                   | 1716 ( 3.5%)\      |          |         |
## |    |                                     | 8\. Chevrolet\                  | 1541 ( 3.2%)\      |          |         |
## |    |                                     | 9\. Mazda\                      | 1533 ( 3.1%)\      |          |         |
## |    |                                     | 10\. Land Rover\                | 1482 ( 3.0%)\      |          |         |
## |    |                                     | 11\. Lincoln\                   | 1418 ( 2.9%)\      |          |         |
## |    |                                     | 12\. Volkswagen\                | 1369 ( 2.8%)\      |          |         |
## |    |                                     | 13\. Nissan\                    | 1152 ( 2.4%)\      |          |         |
## |    |                                     | 14\. Jaguar\                    | 1140 ( 2.3%)\      |          |         |
## |    |                                     | 15\. Infiniti\                  | 1023 ( 2.1%)\      |          |         |
## |    |                                     | 16\. Porsche\                   | 997 ( 2.0%)\       |          |         |
## |    |                                     | 17\. Hyundai\                   | 937 ( 1.9%)\       |          |         |
## |    |                                     | 18\. Chrysler\                  | 909 ( 1.9%)\       |          |         |
## |    |                                     | 19\. Subaru\                    | 908 ( 1.9%)\       |          |         |
## |    |                                     | 20\. Kia\                       | 897 ( 1.8%)\       |          |         |
## |    |                                     | 21\. Gmc\                       | 847 ( 1.7%)\       |          |         |
## |    |                                     | 22\. Ford\                      | 796 ( 1.6%)\       |          |         |
## |    |                                     | 23\. Acura\                     | 777 ( 1.6%)\       |          |         |
## |    |                                     | 24\. Honda\                     | 575 ( 1.2%)\       |          |         |
## |    |                                     | 25\. Tesla\                     | 501 ( 1.0%)\       |          |         |
## |    |                                     | 26\. Buick\                     | 438 ( 0.9%)\       |          |         |
## |    |                                     | 27\. Genesis\                   | 379 ( 0.8%)\       |          |         |
## |    |                                     | 28\. Mini\                      | 247 ( 0.5%)\       |          |         |
## |    |                                     | 29\. Mitsubishi\                | 238 ( 0.5%)\       |          |         |
## |    |                                     | 30\. Dodge\                     | 208 ( 0.4%)\       |          |         |
## |    |                                     | 31\. Genesis Transit Buses\     | 161 ( 0.3%)\       |          |         |
## |    |                                     | 32\. Ram\                       | 158 ( 0.3%)\       |          |         |
## |    |                                     | 33\. Freightliner\              | 155 ( 0.3%)\       |          |         |
## |    |                                     | 34\. Alfa Romeo\                | 154 ( 0.3%)\       |          |         |
## |    |                                     | 35\. Jeep\                      | 95 ( 0.2%)\        |          |         |
## |    |                                     | 36\. Gillig\                    | 69 ( 0.1%)\        |          |         |
## |    |                                     | 37\. Fiat\                      | 65 ( 0.1%)\        |          |         |
## |    |                                     | 38\. Maserati\                  | 60 ( 0.1%)\        |          |         |
## |    |                                     | 39\. Bentley\                   | 39 ( 0.1%)\        |          |         |
## |    |                                     | 40\. Peugeot\                   | 32 ( 0.1%)\        |          |         |
## |    |                                     | 41\. Smart\                     | 27 ( 0.1%)\        |          |         |
## |    |                                     | 42\. New Flyer\                 | 20 ( 0.0%)\        |          |         |
## |    |                                     | 43\. Nova Bus Corporation\      | 9 ( 0.0%)\         |          |         |
## |    |                                     | 44\. Hino\                      | 8 ( 0.0%)\         |          |         |
## |    |                                     | 45\. Renault\                   | 6 ( 0.0%)\         |          |         |
## |    |                                     | 46\. Sprinter\                  | 6 ( 0.0%)\         |          |         |
## |    |                                     | 47\. Fisker Automotive\         | 4 ( 0.0%)\         |          |         |
## |    |                                     | 48\. Suzuki\                    | 4 ( 0.0%)\         |          |         |
## |    |                                     | 49\. Van Hool\                  | 4 ( 0.0%)\         |          |         |
## |    |                                     | 50\. American Motors\           | 3 ( 0.0%)\         |          |         |
## |    |                                     | 51\. Scania\                    | 2 ( 0.0%)\         |          |         |
## |    |                                     | 52\. Maybach\                   | 1 ( 0.0%)\         |          |         |
## |    |                                     | 53\. Mercury\                   | 1 ( 0.0%)\         |          |         |
## |    |                                     | 54\. Ontario Bus                | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 30 | Veh_Body_Styl_ID\                   | 1\. Passenger Car, 4-Door\      | 25851 (52.9%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Sport Utility Vehicle\      | 13216 (27.1%)\     | (100.0%) | (0.0%)  |
## |    |                                     | 3\. Passenger Car, 2-Door\      | 4881 (10.0%)\      |          |         |
## |    |                                     | 4\. Pickup\                     | 1208 ( 2.5%)\      |          |         |
## |    |                                     | 5\. Van\                        | 1189 ( 2.4%)\      |          |         |
## |    |                                     | 6\. Truck Tractor\              | 1141 ( 2.3%)\      |          |         |
## |    |                                     | 7\. Truck\                      | 417 ( 0.9%)\       |          |         |
## |    |                                     | 8\. Unknown\                    | 346 ( 0.7%)\       |          |         |
## |    |                                     | 9\. Bus\                        | 191 ( 0.4%)\       |          |         |
## |    |                                     | 10\. Motorcycle\                | 162 ( 0.3%)\       |          |         |
## |    |                                     | 11\. Other (Explain In Narrati\ | 94 ( 0.2%)\        |          |         |
## |    |                                     | 12\. Police Car/Truck\          | 90 ( 0.2%)\        |          |         |
## |    |                                     | 13\. Ambulance\                 | 40 ( 0.1%)\        |          |         |
## |    |                                     | 14\. Yellow School Bus\         | 8 ( 0.0%)\         |          |         |
## |    |                                     | 15\. Police Motorcycle\         | 3 ( 0.0%)\         |          |         |
## |    |                                     | 16\. Nev-Neighborhood Electric  | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 31 | Emer_Respndr_Fl\                    | 1\. N\                          | 48737 (99.8%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Y                           | 101 ( 0.2%)        | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 32 | Contrib_Factr_1_ID\                 | 1\. None\                       | 27384 (58.1%)\     | 47168\   | 1670\   |
## |    | [factor]                            | 2\. Failed To Control Speed\    | 3445 ( 7.3%)\      | (96.6%)  | (3.4%)  |
## |    |                                     | 3\. Driver Inattention\         | 2026 ( 4.3%)\      |          |         |
## |    |                                     | 4\. Other (Explain In Narrati\  | 1945 ( 4.1%)\      |          |         |
## |    |                                     | 5\. Changed Lane When Unsafe\   | 1643 ( 3.5%)\      |          |         |
## |    |                                     | 6\. Failed To Yield Right Of \  | 1198 ( 2.5%)\      |          |         |
## |    |                                     | 7\. Failed To Drive In Single\  | 1031 ( 2.2%)\      |          |         |
## |    |                                     | 8\. Failed To Yield Right Of \  | 1002 ( 2.1%)\      |          |         |
## |    |                                     | 9\. Disregard Stop And Go Sig\  | 661 ( 1.4%)\       |          |         |
## |    |                                     | 10\. Failed To Yield Right Of \ | 625 ( 1.3%)\       |          |         |
## |    |                                     | 11\. Unsafe Speed\              | 561 ( 1.2%)\       |          |         |
## |    |                                     | 12\. Backed Without Safety\     | 546 ( 1.2%)\       |          |         |
## |    |                                     | 13\. Followed Too Closely\      | 481 ( 1.0%)\       |          |         |
## |    |                                     | 14\. Disregard Stop Sign Or Li\ | 432 ( 0.9%)\       |          |         |
## |    |                                     | 15\. Faulty Evasive Action\     | 370 ( 0.8%)\       |          |         |
## |    |                                     | 16\. Turned When Unsafe\        | 353 ( 0.7%)\       |          |         |
## |    |                                     | 17\. Under Influence - Alcohol\ | 350 ( 0.7%)\       |          |         |
## |    |                                     | 18\. Animal On Road - Wild\     | 289 ( 0.6%)\       |          |         |
## |    |                                     | 19\. Turned Improperly - Wrong\ | 263 ( 0.6%)\       |          |         |
## |    |                                     | 20\. Failed To Yield Right Of \ | 240 ( 0.5%)\       |          |         |
## |    |                                     | 21\. Distraction In Vehicle\    | 216 ( 0.5%)\       |          |         |
## |    |                                     | 22\. Had Been Drinking\         | 140 ( 0.3%)\       |          |         |
## |    |                                     | 23\. Fatigued Or Asleep\        | 139 ( 0.3%)\       |          |         |
## |    |                                     | 24\. Turned Improperly - Wide \ | 132 ( 0.3%)\       |          |         |
## |    |                                     | 25\. Failed To Pass To Left Sa\ | 111 ( 0.2%)\       |          |         |
## |    |                                     | 26\. Failed To Yield Right Of \ | 104 ( 0.2%)\       |          |         |
## |    |                                     | 27\. Failed To Stop At Proper \ | 101 ( 0.2%)\       |          |         |
## |    |                                     | 28\. Ill (Explain In Narrative\ | 100 ( 0.2%)\       |          |         |
## |    |                                     | 29\. Failed To Yield Right Of \ | 98 ( 0.2%)\        |          |         |
## |    |                                     | 30\. Animal On Road - Domestic\ | 93 ( 0.2%)\        |          |         |
## |    |                                     | 31\. Disregard Turn Marks At I\ | 92 ( 0.2%)\        |          |         |
## |    |                                     | 32\. Improper Start From Parke\ | 81 ( 0.2%)\        |          |         |
## |    |                                     | 33\. Failed To Pass To Right S\ | 70 ( 0.1%)\        |          |         |
## |    |                                     | 34\. Turned Improperly - Cut C\ | 66 ( 0.1%)\        |          |         |
## |    |                                     | 35\. Fleeing Or Evading Police\ | 64 ( 0.1%)\        |          |         |
## |    |                                     | 36\. Failed To Yield Right Of \ | 62 ( 0.1%)\        |          |         |
## |    |                                     | 37\. Impaired Visibility (Expl\ | 57 ( 0.1%)\        |          |         |
## |    |                                     | 38\. Speeding - (Overlimit)\    | 54 ( 0.1%)\        |          |         |
## |    |                                     | 39\. Road Rage\                 | 47 ( 0.1%)\        |          |         |
## |    |                                     | 40\. Failed To Heed Warning Si\ | 43 ( 0.1%)\        |          |         |
## |    |                                     | 41\. Failed To Give Half Of Ro\ | 38 ( 0.1%)\        |          |         |
## |    |                                     | 42\. Disabled In Traffic Lane\  | 34 ( 0.1%)\        |          |         |
## |    |                                     | 43\. Wrong Way - One Way Road\  | 34 ( 0.1%)\        |          |         |
## |    |                                     | 44\. Passed In No Passing Lane\ | 31 ( 0.1%)\        |          |         |
## |    |                                     | 45\. Under Influence - Drug\    | 28 ( 0.1%)\        |          |         |
## |    |                                     | 46\. Wrong Side - Not Passing\  | 26 ( 0.1%)\        |          |         |
## |    |                                     | 47\. Parked In Traffic Lane\    | 25 ( 0.1%)\        |          |         |
## |    |                                     | 48\. Overtake And Pass Insuffi\ | 23 ( 0.0%)\        |          |         |
## |    |                                     | 49\. Passed On Right Shoulder\  | 23 ( 0.0%)\        |          |         |
## |    |                                     | 50\. Cell/Mobile Device Use - \ | 17 ( 0.0%)\        |          |         |
## |    |                                     | 51\. Oversized Vehicle Or Load\ | 15 ( 0.0%)\        |          |         |
## |    |                                     | 52\. Opened Door Into Traffic \ | 14 ( 0.0%)\        |          |         |
## |    |                                     | 53\. Failed To Yield Right Of \ | 13 ( 0.0%)\        |          |         |
## |    |                                     | 54\. Cell/Mobile Device Use - \ | 12 ( 0.0%)\        |          |         |
## |    |                                     | 55\. Failed To Signal Or Gave \ | 12 ( 0.0%)\        |          |         |
## |    |                                     | 56\. Cell/Mobile Device Use - \ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 57\. Pedestrian Failed To Yiel\ | 11 ( 0.0%)\        |          |         |
## |    |                                     | 58\. Disregard Warning Sign At\ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 59\. Drove On Improved Shoulde\ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 60\. Handicapped Driver (Expla\ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 61\. Parked And Failed To Set \ | 10 ( 0.0%)\        |          |         |
## |    |                                     | 62\. Wrong Side - Approach Or \ | 9 ( 0.0%)\         |          |         |
## |    |                                     | 63\. Cell/Mobile Device Use - \ | 6 ( 0.0%)\         |          |         |
## |    |                                     | 64\. Failed To Slow Or Move Ov\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 65\. Fire In Vehicle\           | 5 ( 0.0%)\         |          |         |
## |    |                                     | 66\. Load Not Secured\          | 5 ( 0.0%)\         |          |         |
## |    |                                     | 67\. Taking Medication (Explai\ | 5 ( 0.0%)\         |          |         |
## |    |                                     | 68\. Parked Without Lights\     | 4 ( 0.0%)\         |          |         |
## |    |                                     | 69\. Drove Without Headlights\  | 3 ( 0.0%)\         |          |         |
## |    |                                     | 70\. Failed To Stop For School\ | 3 ( 0.0%)\         |          |         |
## |    |                                     | 71\. Failed To Stop For Train   | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 33 | Contrib_Factr_2_ID\                 | 1\. Driver Inattention\         | 682 (24.8%)\       | 2751\    | 46087\  |
## |    | [factor]                            | 2\. Failed To Control Speed\    | 347 (12.6%)\       | (5.6%)   | (94.4%) |
## |    |                                     | 3\. Failed To Drive In Single\  | 185 ( 6.7%)\       |          |         |
## |    |                                     | 4\. Faulty Evasive Action\      | 177 ( 6.4%)\       |          |         |
## |    |                                     | 5\. Under Influence - Alcohol\  | 134 ( 4.9%)\       |          |         |
## |    |                                     | 6\. Other (Explain In Narrati\  | 108 ( 3.9%)\       |          |         |
## |    |                                     | 7\. Distraction In Vehicle\     | 97 ( 3.5%)\        |          |         |
## |    |                                     | 8\. Unsafe Speed\               | 86 ( 3.1%)\        |          |         |
## |    |                                     | 9\. Followed Too Closely\       | 85 ( 3.1%)\        |          |         |
## |    |                                     | 10\. Changed Lane When Unsafe\  | 83 ( 3.0%)\        |          |         |
## |    |                                     | 11\. Had Been Drinking\         | 66 ( 2.4%)\        |          |         |
## |    |                                     | 12\. Turned When Unsafe\        | 59 ( 2.1%)\        |          |         |
## |    |                                     | 13\. Failed To Yield Right Of \ | 56 ( 2.0%)\        |          |         |
## |    |                                     | 14\. Fatigued Or Asleep\        | 40 ( 1.5%)\        |          |         |
## |    |                                     | 15\. Failed To Yield Right Of \ | 38 ( 1.4%)\        |          |         |
## |    |                                     | 16\. Turned Improperly - Wide \ | 36 ( 1.3%)\        |          |         |
## |    |                                     | 17\. Disregard Stop Sign Or Li\ | 34 ( 1.2%)\        |          |         |
## |    |                                     | 18\. Failed To Yield Right Of \ | 29 ( 1.1%)\        |          |         |
## |    |                                     | 19\. Impaired Visibility (Expl\ | 27 ( 1.0%)\        |          |         |
## |    |                                     | 20\. Turned Improperly - Wrong\ | 26 ( 0.9%)\        |          |         |
## |    |                                     | 21\. Failed To Stop At Proper \ | 24 ( 0.9%)\        |          |         |
## |    |                                     | 22\. Under Influence - Drug\    | 24 ( 0.9%)\        |          |         |
## |    |                                     | 23\. Disregard Stop And Go Sig\ | 23 ( 0.8%)\        |          |         |
## |    |                                     | 24\. Ill (Explain In Narrative\ | 23 ( 0.8%)\        |          |         |
## |    |                                     | 25\. Speeding - (Overlimit)\    | 21 ( 0.8%)\        |          |         |
## |    |                                     | 26\. Failed To Yield Right Of \ | 18 ( 0.7%)\        |          |         |
## |    |                                     | 27\. Backed Without Safety\     | 15 ( 0.5%)\        |          |         |
## |    |                                     | 28\. Cell/Mobile Device Use - \ | 15 ( 0.5%)\        |          |         |
## |    |                                     | 29\. Fleeing Or Evading Police\ | 12 ( 0.4%)\        |          |         |
## |    |                                     | 30\. Cell/Mobile Device Use - \ | 11 ( 0.4%)\        |          |         |
## |    |                                     | 31\. Cell/Mobile Device Use - \ | 11 ( 0.4%)\        |          |         |
## |    |                                     | 32\. Disregard Turn Marks At I\ | 11 ( 0.4%)\        |          |         |
## |    |                                     | 33\. Failed To Pass To Left Sa\ | 11 ( 0.4%)\        |          |         |
## |    |                                     | 34\. Wrong Way - One Way Road\  | 10 ( 0.4%)\        |          |         |
## |    |                                     | 35\. Wrong Side - Not Passing\  | 9 ( 0.3%)\         |          |         |
## |    |                                     | 36\. Animal On Road - Domestic\ | 8 ( 0.3%)\         |          |         |
## |    |                                     | 37\. Failed To Pass To Right S\ | 8 ( 0.3%)\         |          |         |
## |    |                                     | 38\. Failed To Yield Right Of \ | 8 ( 0.3%)\         |          |         |
## |    |                                     | 39\. Turned Improperly - Cut C\ | 8 ( 0.3%)\         |          |         |
## |    |                                     | 40\. Overtake And Pass Insuffi\ | 7 ( 0.3%)\         |          |         |
## |    |                                     | 41\. Road Rage\                 | 7 ( 0.3%)\         |          |         |
## |    |                                     | 42\. Passed In No Passing Lane\ | 6 ( 0.2%)\         |          |         |
## |    |                                     | 43\. Failed To Give Half Of Ro\ | 5 ( 0.2%)\         |          |         |
## |    |                                     | 44\. Failed To Heed Warning Si\ | 5 ( 0.2%)\         |          |         |
## |    |                                     | 45\. Improper Start From Parke\ | 5 ( 0.2%)\         |          |         |
## |    |                                     | 46\. Animal On Road - Wild\     | 4 ( 0.1%)\         |          |         |
## |    |                                     | 47\. Drove On Improved Shoulde\ | 4 ( 0.1%)\         |          |         |
## |    |                                     | 48\. Failed To Yield Right Of \ | 4 ( 0.1%)\         |          |         |
## |    |                                     | 49\. Failed To Yield Right Of \ | 4 ( 0.1%)\         |          |         |
## |    |                                     | 50\. Failed To Yield Right Of \ | 4 ( 0.1%)\         |          |         |
## |    |                                     | 51\. Passed On Right Shoulder\  | 4 ( 0.1%)\         |          |         |
## |    |                                     | 52\. Wrong Side - Approach Or \ | 4 ( 0.1%)\         |          |         |
## |    |                                     | 53\. Cell/Mobile Device Use - \ | 3 ( 0.1%)\         |          |         |
## |    |                                     | 54\. Disregard Warning Sign At\ | 3 ( 0.1%)\         |          |         |
## |    |                                     | 55\. Failed To Signal Or Gave \ | 3 ( 0.1%)\         |          |         |
## |    |                                     | 56\. Failed To Slow Or Move Ov\ | 3 ( 0.1%)\         |          |         |
## |    |                                     | 57\. Drove Without Headlights\  | 2 ( 0.1%)\         |          |         |
## |    |                                     | 58\. Pedestrian Failed To Yiel\ | 2 ( 0.1%)\         |          |         |
## |    |                                     | 59\. Disabled In Traffic Lane\  | 1 ( 0.0%)\         |          |         |
## |    |                                     | 60\. Failed To Stop For School\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 61\. Load Not Secured\          | 1 ( 0.0%)\         |          |         |
## |    |                                     | 62\. Opened Door Into Traffic \ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 63\. Oversized Vehicle Or Load\ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 64\. Parked And Failed To Set \ | 1 ( 0.0%)\         |          |         |
## |    |                                     | 65\. Parked In Traffic Lane     | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 34 | Prsn_Type_ID\                       | 1\. Driver\                     | 45350 (98.7%)\     | 45943\   | 2895\   |
## |    | [factor]                            | 2\. Passenger/Occupant\         | 258 ( 0.6%)\       | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Unknown\                    | 172 ( 0.4%)\       |          |         |
## |    |                                     | 4\. Driver Of Motorcycle Type\  | 162 ( 0.4%)\       |          |         |
## |    |                                     | 5\. Passenger/Occupant On Mot   | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 35 | Prsn_Injry_Sev_ID\                  | 1\. Not Injured\                | 37024 (80.6%)\     | 45943\   | 2895\   |
## |    | [factor]                            | 2\. Possible Injury\            | 3923 ( 8.5%)\      | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Non-Incapacitating Injury\  | 2373 ( 5.2%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 2230 ( 4.9%)\      |          |         |
## |    |                                     | 5\. Incapacitating Injury\      | 346 ( 0.8%)\       |          |         |
## |    |                                     | 6\. Killed                      | 47 ( 0.1%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 36 | Prsn_Age\                           | 1\. 46\                         | 970 (2.2%)\        | 43984\   | 4854\   |
## |    | [factor]                            | 2\. 39\                         | 964 (2.2%)\        | (90.1%)  | (9.9%)  |
## |    |                                     | 3\. 33\                         | 963 (2.2%)\        |          |         |
## |    |                                     | 4\. 31\                         | 962 (2.2%)\        |          |         |
## |    |                                     | 5\. 36\                         | 950 (2.2%)\        |          |         |
## |    |                                     | 6\. 43\                         | 945 (2.1%)\        |          |         |
## |    |                                     | 7\. 37\                         | 944 (2.1%)\        |          |         |
## |    |                                     | 8\. 34\                         | 940 (2.1%)\        |          |         |
## |    |                                     | 9\. 40\                         | 934 (2.1%)\        |          |         |
## |    |                                     | 10\. 41\                        | 931 (2.1%)\        |          |         |
## |    |                                     | 11\. 42\                        | 928 (2.1%)\        |          |         |
## |    |                                     | 12\. 38\                        | 926 (2.1%)\        |          |         |
## |    |                                     | 13\. 29\                        | 924 (2.1%)\        |          |         |
## |    |                                     | 14\. 35\                        | 917 (2.1%)\        |          |         |
## |    |                                     | 15\. 26\                        | 907 (2.1%)\        |          |         |
## |    |                                     | 16\. 44\                        | 904 (2.1%)\        |          |         |
## |    |                                     | 17\. 30\                        | 903 (2.1%)\        |          |         |
## |    |                                     | 18\. 45\                        | 898 (2.0%)\        |          |         |
## |    |                                     | 19\. 27\                        | 880 (2.0%)\        |          |         |
## |    |                                     | 20\. 32\                        | 876 (2.0%)\        |          |         |
## |    |                                     | 21\. 23\                        | 874 (2.0%)\        |          |         |
## |    |                                     | 22\. 48\                        | 856 (1.9%)\        |          |         |
## |    |                                     | 23\. 25\                        | 853 (1.9%)\        |          |         |
## |    |                                     | 24\. 28\                        | 841 (1.9%)\        |          |         |
## |    |                                     | 25\. 47\                        | 841 (1.9%)\        |          |         |
## |    |                                     | 26\. 50\                        | 840 (1.9%)\        |          |         |
## |    |                                     | 27\. 24\                        | 828 (1.9%)\        |          |         |
## |    |                                     | 28\. 49\                        | 820 (1.9%)\        |          |         |
## |    |                                     | 29\. 51\                        | 814 (1.9%)\        |          |         |
## |    |                                     | 30\. 52\                        | 795 (1.8%)\        |          |         |
## |    |                                     | 31\. 22\                        | 775 (1.8%)\        |          |         |
## |    |                                     | 32\. 53\                        | 761 (1.7%)\        |          |         |
## |    |                                     | 33\. 54\                        | 723 (1.6%)\        |          |         |
## |    |                                     | 34\. 55\                        | 708 (1.6%)\        |          |         |
## |    |                                     | 35\. 21\                        | 695 (1.6%)\        |          |         |
## |    |                                     | 36\. 19\                        | 684 (1.6%)\        |          |         |
## |    |                                     | 37\. 20\                        | 683 (1.6%)\        |          |         |
## |    |                                     | 38\. 56\                        | 668 (1.5%)\        |          |         |
## |    |                                     | 39\. 57\                        | 649 (1.5%)\        |          |         |
## |    |                                     | 40\. 18\                        | 629 (1.4%)\        |          |         |
## |    |                                     | 41\. 59\                        | 626 (1.4%)\        |          |         |
## |    |                                     | 42\. 58\                        | 597 (1.4%)\        |          |         |
## |    |                                     | 43\. 17\                        | 567 (1.3%)\        |          |         |
## |    |                                     | 44\. 60\                        | 557 (1.3%)\        |          |         |
## |    |                                     | 45\. 61\                        | 537 (1.2%)\        |          |         |
## |    |                                     | 46\. 62\                        | 537 (1.2%)\        |          |         |
## |    |                                     | 47\. 64\                        | 493 (1.1%)\        |          |         |
## |    |                                     | 48\. 63\                        | 476 (1.1%)\        |          |         |
## |    |                                     | 49\. 16\                        | 428 (1.0%)\        |          |         |
## |    |                                     | 50\. 65\                        | 417 (0.9%)\        |          |         |
## |    |                                     | 51\. 66\                        | 415 (0.9%)\        |          |         |
## |    |                                     | 52\. 67\                        | 398 (0.9%)\        |          |         |
## |    |                                     | 53\. 68\                        | 384 (0.9%)\        |          |         |
## |    |                                     | 54\. 69\                        | 374 (0.9%)\        |          |         |
## |    |                                     | 55\. 70\                        | 336 (0.8%)\        |          |         |
## |    |                                     | 56\. 71\                        | 302 (0.7%)\        |          |         |
## |    |                                     | 57\. 72\                        | 297 (0.7%)\        |          |         |
## |    |                                     | 58\. 73\                        | 272 (0.6%)\        |          |         |
## |    |                                     | 59\. 74\                        | 250 (0.6%)\        |          |         |
## |    |                                     | 60\. 76\                        | 228 (0.5%)\        |          |         |
## |    |                                     | 61\. 75\                        | 219 (0.5%)\        |          |         |
## |    |                                     | 62\. 77\                        | 193 (0.4%)\        |          |         |
## |    |                                     | 63\. 79\                        | 167 (0.4%)\        |          |         |
## |    |                                     | 64\. 78\                        | 166 (0.4%)\        |          |         |
## |    |                                     | 65\. 81\                        | 124 (0.3%)\        |          |         |
## |    |                                     | 66\. 80\                        | 121 (0.3%)\        |          |         |
## |    |                                     | 67\. 82\                        | 109 (0.2%)\        |          |         |
## |    |                                     | 68\. 83\                        | 78 (0.2%)\         |          |         |
## |    |                                     | 69\. 84\                        | 75 (0.2%)\         |          |         |
## |    |                                     | 70\. 85\                        | 73 (0.2%)\         |          |         |
## |    |                                     | 71\. 15\                        | 46 (0.1%)\         |          |         |
## |    |                                     | 72\. 86\                        | 43 (0.1%)\         |          |         |
## |    |                                     | 73\. 87\                        | 43 (0.1%)\         |          |         |
## |    |                                     | 74\. 88\                        | 31 (0.1%)\         |          |         |
## |    |                                     | 75\. 89\                        | 18 (0.0%)\         |          |         |
## |    |                                     | 76\. 90\                        | 15 (0.0%)\         |          |         |
## |    |                                     | 77\. 91\                        | 12 (0.0%)\         |          |         |
## |    |                                     | 78\. 14\                        | 11 (0.0%)\         |          |         |
## |    |                                     | 79\. 99\                        | 11 (0.0%)\         |          |         |
## |    |                                     | 80\. 92\                        | 8 (0.0%)\          |          |         |
## |    |                                     | 81\. 94\                        | 5 (0.0%)\          |          |         |
## |    |                                     | 82\. 1\                         | 4 (0.0%)\          |          |         |
## |    |                                     | 83\. 93\                        | 4 (0.0%)\          |          |         |
## |    |                                     | 84\. 95\                        | 4 (0.0%)\          |          |         |
## |    |                                     | 85\. 100\                       | 4 (0.0%)\          |          |         |
## |    |                                     | 86\. 13\                        | 2 (0.0%)\          |          |         |
## |    |                                     | 87\. 4\                         | 1 (0.0%)\          |          |         |
## |    |                                     | 88\. 96\                        | 1 (0.0%)\          |          |         |
## |    |                                     | 89\. 97\                        | 1 (0.0%)\          |          |         |
## |    |                                     | 90\. 117                        | 1 (0.0%)           |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 37 | Prsn_Ethnicity_ID\                  | 1\. White\                      | 21201 (46.4%)\     | 45697\   | 3141\   |
## |    | [factor]                            | 2\. Hispanic\                   | 9547 (20.9%)\      | (93.6%)  | (6.4%)  |
## |    |                                     | 3\. Black\                      | 8149 (17.8%)\      |          |         |
## |    |                                     | 4\. Asian\                      | 4148 ( 9.1%)\      |          |         |
## |    |                                     | 5\. Unknown\                    | 1646 ( 3.6%)\      |          |         |
## |    |                                     | 6\. Other\                      | 694 ( 1.5%)\       |          |         |
## |    |                                     | 7\. Amer. Indian/Alaskan Nati   | 312 ( 0.7%)        |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 38 | Prsn_Gndr_ID\                       | 1\. Male\                       | 24018 (52.3%)\     | 45943\   | 2895\   |
## |    | [factor]                            | 2\. Female\                     | 20634 (44.9%)\     | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Unknown                     | 1291 ( 2.8%)       |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 39 | Prsn_Ejct_ID\                       | 1\. No\                         | 43653 (95.0%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. Unknown\                    | 1355 ( 2.9%)\      | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Not Applicable\             | 783 ( 1.7%)\       |          |         |
## |    |                                     | 4\. Yes\                        | 146 ( 0.3%)\       |          |         |
## |    |                                     | 5\. Yes, Partial                | 8 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 40 | Prsn_Rest_ID\                       | 1\. Shoulder & Lap Belt\        | 41243 (89.8%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. Unknown\                    | 3701 ( 8.1%)\      | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Not Applicable\             | 421 ( 0.9%)\       |          |         |
## |    |                                     | 4\. Shoulder Belt Only\         | 272 ( 0.6%)\       |          |         |
## |    |                                     | 5\. None\                       | 248 ( 0.5%)\       |          |         |
## |    |                                     | 6\. Lap Belt Only\              | 24 ( 0.1%)\        |          |         |
## |    |                                     | 7\. Other (Explain In Narrati\  | 24 ( 0.1%)\        |          |         |
## |    |                                     | 8\. Child Seat, Unknown\        | 5 ( 0.0%)\         |          |         |
## |    |                                     | 9\. Child Seat, Facing Forwar\  | 4 ( 0.0%)\         |          |         |
## |    |                                     | 10\. Child Seat, Facing Rear\   | 2 ( 0.0%)\         |          |         |
## |    |                                     | 11\. Child Booster Seat         | 1 ( 0.0%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 41 | Prsn_Airbag_ID\                     | 1\. Not Deployed\               | 34161 (74.4%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. Deployed, Multiple\         | 5198 (11.3%)\      | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Deployed, Front\            | 2800 ( 6.1%)\      |          |         |
## |    |                                     | 4\. Unknown\                    | 1936 ( 4.2%)\      |          |         |
## |    |                                     | 5\. Deployed, Side\             | 1203 ( 2.6%)\      |          |         |
## |    |                                     | 6\. Not Applicable\             | 630 ( 1.4%)\       |          |         |
## |    |                                     | 7\. Deployed, Rear              | 17 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 42 | Prsn_Helmet_ID\                     | 1\. Not Applicable\             | 45741 (99.6%)\     | 45945\   | 2893\   |
## |    | [factor]                            | 2\. Not Worn\                   | 73 ( 0.2%)\        | (94.1%)  | (5.9%)  |
## |    |                                     | 3\. Worn, Damaged\              | 50 ( 0.1%)\        |          |         |
## |    |                                     | 4\. Worn, Not Damaged\          | 45 ( 0.1%)\        |          |         |
## |    |                                     | 5\. Worn, Unk Damage\           | 23 ( 0.1%)\        |          |         |
## |    |                                     | 6\. Unknown If Worn             | 13 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 43 | Drvr_Lic_Type_ID\                   | 1\. Driver License\             | 40980 (89.9%)\     | 45570\   | 3268\   |
## |    | [factor]                            | 2\. Unknown\                    | 1836 ( 4.0%)\      | (93.3%)  | (6.7%)  |
## |    |                                     | 3\. Commercial Driver Lic.\     | 1450 ( 3.2%)\      |          |         |
## |    |                                     | 4\. Unlicensed\                 | 657 ( 1.4%)\       |          |         |
## |    |                                     | 5\. Id Card\                    | 528 ( 1.2%)\       |          |         |
## |    |                                     | 6\. Other\                      | 108 ( 0.2%)\       |          |         |
## |    |                                     | 7\. Occupational                | 11 ( 0.0%)         |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 44 | E_Scooter_ID\                       | 1\. Not Applicable\             | 36360 (74.5%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. Data Not Available At Dat   | 12478 (25.5%)      | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 45 | n_crashes\                          | 1\. 51\                         | 1122 (2.3%)\       | 48838\   | 0\      |
## |    | [factor]                            | 2\. 33\                         | 1089 (2.2%)\       | (100.0%) | (0.0%)  |
## |    |                                     | 3\. 34\                         | 1056 (2.2%)\       |          |         |
## |    |                                     | 4\. 37\                         | 1036 (2.1%)\       |          |         |
## |    |                                     | 5\. 38\                         | 1033 (2.1%)\       |          |         |
## |    |                                     | 6\. 10\                         | 1010 (2.1%)\       |          |         |
## |    |                                     | 7\. 53\                         | 1007 (2.1%)\       |          |         |
## |    |                                     | 8\. 31\                         | 992 (2.0%)\        |          |         |
## |    |                                     | 9\. 45\                         | 990 (2.0%)\        |          |         |
## |    |                                     | 10\. 49\                        | 980 (2.0%)\        |          |         |
## |    |                                     | 11\. 54\                        | 972 (2.0%)\        |          |         |
## |    |                                     | 12\. 26\                        | 962 (2.0%)\        |          |         |
## |    |                                     | 13\. 48\                        | 960 (2.0%)\        |          |         |
## |    |                                     | 14\. 3\                         | 952 (1.9%)\        |          |         |
## |    |                                     | 15\. 20\                        | 941 (1.9%)\        |          |         |
## |    |                                     | 16\. 5\                         | 935 (1.9%)\        |          |         |
## |    |                                     | 17\. 2\                         | 930 (1.9%)\        |          |         |
## |    |                                     | 18\. 25\                        | 927 (1.9%)\        |          |         |
## |    |                                     | 19\. 28\                        | 924 (1.9%)\        |          |         |
## |    |                                     | 20\. 9\                         | 918 (1.9%)\        |          |         |
## |    |                                     | 21\. 15\                        | 916 (1.9%)\        |          |         |
## |    |                                     | 22\. 7\                         | 910 (1.9%)\        |          |         |
## |    |                                     | 23\. 13\                        | 910 (1.9%)\        |          |         |
## |    |                                     | 24\. 4\                         | 901 (1.8%)\        |          |         |
## |    |                                     | 25\. 30\                        | 900 (1.8%)\        |          |         |
## |    |                                     | 26\. 39\                        | 897 (1.8%)\        |          |         |
## |    |                                     | 27\. 16\                        | 896 (1.8%)\        |          |         |
## |    |                                     | 28\. 6\                         | 894 (1.8%)\        |          |         |
## |    |                                     | 29\. 8\                         | 880 (1.8%)\        |          |         |
## |    |                                     | 30\. 58\                        | 870 (1.8%)\        |          |         |
## |    |                                     | 31\. 17\                        | 867 (1.8%)\        |          |         |
## |    |                                     | 32\. 41\                        | 861 (1.8%)\        |          |         |
## |    |                                     | 33\. 22\                        | 859 (1.8%)\        |          |         |
## |    |                                     | 34\. 40\                        | 840 (1.7%)\        |          |         |
## |    |                                     | 35\. 12\                        | 828 (1.7%)\        |          |         |
## |    |                                     | 36\. 18\                        | 828 (1.7%)\        |          |         |
## |    |                                     | 37\. 11\                        | 814 (1.7%)\        |          |         |
## |    |                                     | 38\. 50\                        | 800 (1.6%)\        |          |         |
## |    |                                     | 39\. 21\                        | 798 (1.6%)\        |          |         |
## |    |                                     | 40\. 1\                         | 789 (1.6%)\        |          |         |
## |    |                                     | 41\. 47\                        | 752 (1.5%)\        |          |         |
## |    |                                     | 42\. 32\                        | 736 (1.5%)\        |          |         |
## |    |                                     | 43\. 52\                        | 728 (1.5%)\        |          |         |
## |    |                                     | 44\. 56\                        | 728 (1.5%)\        |          |         |
## |    |                                     | 45\. 42\                        | 714 (1.5%)\        |          |         |
## |    |                                     | 46\. 29\                        | 696 (1.4%)\        |          |         |
## |    |                                     | 47\. 43\                        | 688 (1.4%)\        |          |         |
## |    |                                     | 48\. 19\                        | 684 (1.4%)\        |          |         |
## |    |                                     | 49\. 27\                        | 675 (1.4%)\        |          |         |
## |    |                                     | 50\. 14\                        | 672 (1.4%)\        |          |         |
## |    |                                     | 51\. 55\                        | 660 (1.4%)\        |          |         |
## |    |                                     | 52\. 36\                        | 649 (1.3%)\        |          |         |
## |    |                                     | 53\. 23\                        | 621 (1.3%)\        |          |         |
## |    |                                     | 54\. 44\                        | 616 (1.3%)\        |          |         |
## |    |                                     | 55\. 46\                        | 598 (1.2%)\        |          |         |
## |    |                                     | 56\. 35\                        | 560 (1.1%)\        |          |         |
## |    |                                     | 57\. 24\                        | 552 (1.1%)\        |          |         |
## |    |                                     | 58\. 57\                        | 456 (0.9%)\        |          |         |
## |    |                                     | 59\. 59                         | 59 (0.1%)          |          |         |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 46 | IsElectric\                         | 1\. FALSE\                      | 47161 (96.6%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. TRUE                        | 1677 ( 3.4%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 47 | IsHybrid\                           | 1\. FALSE\                      | 41114 (84.2%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. TRUE                        | 7724 (15.8%)       | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 48 | HasAutomaticBrakingSystem\          | 1\. TRUE\                       | 38165 (78.1%)\     | 48838\   | 0\      |
## |    | [factor]                            | 2\. FALSE                       | 10673 (21.9%)      | (100.0%) | (0.0%)  |
## +----+-------------------------------------+---------------------------------+--------------------+----------+---------+
## | 49 | HasAutomaticEmergencyBrakingSystem\ | 1\. TRUE                        | 48838 (100.0%)     | 48838\   | 0\      |
## |    | [factor]                            |                                 |                    | (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
  )