Loading in and transposing excel table to data frame

You have not provided representative data that would allow your code to run, (to demonstrate it works) , or which the forum users might try to run their own attempts to improve on your code.
Please review the best practice for providing representative data to the forum as per this document

link

The short of it will be that where in your code you read an excel file (that we dont have) :

accidents <- read_xlsx("input\\accidents data.xlsx", sheet = "accidents", 
                        range = cell_limits(c(3, 1), c(NA, NA)))

this is the point at which you would provide "data as code", by using dput() on accidents, so that you can substitute this for the read_xlsx call.