Skip to contents

Format STATS19 'collisions' data

Usage

format_collisions(x)

Arguments

x

Data frame created with read_collisions()

Details

This is a helper function to format raw STATS19 data

Examples

# \donttest{
if(curl::has_internet()) {
dl_stats19(year = 2022, type = "collision")
x = read_collisions(year = 2022, format = FALSE)
x = readr::read_csv("https://github.com/ropensci/stats19/releases/download/v3.0.0/fatalities.csv")
if(nrow(x) > 0) {
x[1:3, 1:12]
crashes = format_collisions(x)
crashes[1:3, 1:12]
summary(crashes$datetime)
}
}
#> Files identified: dft-road-casualty-statistics-collision-2022.csv
#>    https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-collision-2022.csv
#> Attempt downloading from: https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-collision-2022.csv
#> Data saved at /tmp/Rtmpc4SGfV/dft-road-casualty-statistics-collision-2022.csv
#> Reading in: 
#> /tmp/Rtmpc4SGfV/dft-road-casualty-statistics-collision-2022.csv
#> Rows: 106004 Columns: 36
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr   (6): accident_index, accident_reference, date, local_authority_ons_dis...
#> dbl  (29): accident_year, location_easting_osgr, location_northing_osgr, lon...
#> time  (1): time
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 141698 Columns: 37
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr  (30): accident_index, accident_reference, location_easting_osgr, locati...
#> dbl   (4): accident_year, number_of_vehicles, number_of_casualties, speed_limit
#> dttm  (1): datetime
#> date  (1): date
#> time  (1): time
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> date and time columns present, creating formatted datetime column
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#>     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
#>       NA       NA       NA    "NaN"       NA       NA "141698" 
# }