Format STATS19 'accidents' data

format_accidents(x)

Arguments

x

Data frame created with read_accidents()

Details

This is a helper function to format raw STATS19 data

Examples

# \donttest{ dl_stats19(year = 2017, type = "accident")
#> Files identified: dftRoadSafetyData_Accidents_2017.zip
#> http://data.dft.gov.uk.s3.amazonaws.com/road-accidents-safety-data/dftRoadSafetyData_Accidents_2017.zip
#> Data already exists in data_dir, not downloading
#> Data saved at /tmp/RtmpPSYWX6/dftRoadSafetyData_Accidents_2017/Acc.csv
x = read_accidents(year = 2017, format = FALSE)
#> Reading in:
#> /tmp/RtmpPSYWX6/dftRoadSafetyData_Accidents_2017/Acc.csv
x[1:3, 1:12]
#> # A tibble: 3 x 12 #> Accident_Index Location_Eastin… Location_Northi… Longitude Latitude #> <chr> <int> <int> <dbl> <dbl> #> 1 2017010001708 532920 196330 -0.0801 51.7 #> 2 2017010009342 526790 181970 -0.174 51.5 #> 3 2017010009344 535200 181260 -0.0530 51.5 #> # … with 7 more variables: Police_Force <int>, Accident_Severity <int>, #> # Number_of_Vehicles <int>, Number_of_Casualties <int>, Date <chr>, #> # Day_of_Week <int>, Time <chr>
crashes = format_accidents(x)
#> date and time columns present, creating formatted datetime column
crashes[1:3, 1:12]
#> # A tibble: 3 x 12 #> accident_index location_eastin… location_northi… longitude latitude #> <chr> <int> <int> <dbl> <dbl> #> 1 2017010001708 532920 196330 -0.0801 51.7 #> 2 2017010009342 526790 181970 -0.174 51.5 #> 3 2017010009344 535200 181260 -0.0530 51.5 #> # … with 7 more variables: police_force <chr>, accident_severity <chr>, #> # number_of_vehicles <int>, number_of_casualties <int>, date <date>, #> # day_of_week <chr>, time <chr>
summary(crashes$datetime)
#> Min. 1st Qu. Median #> "2017-01-01 00:05:00" "2017-04-03 12:22:30" "2017-07-04 20:38:00" #> Mean 3rd Qu. Max. #> "2017-07-04 03:05:53" "2017-10-04 12:15:00" "2017-12-31 23:31:00" #> NA's #> "3"
# }