Skip to contents

Format STATS19 'accidents' data

Usage

format_accidents(x)

Arguments

x

Data frame created with read_accidents()

Details

This is a helper function to format raw STATS19 data

Examples

# \donttest{
if(curl::has_internet()) {
dl_stats19(year = 2017, type = "accident")
x = read_accidents(year = 2017, format = FALSE)
if(nrow(x) > 0) {
x[1:3, 1:12]
crashes = format_accidents(x)
crashes[1:3, 1:12]
summary(crashes$datetime)
}
}
#> Files identified: dft-road-casualty-statistics-accident-2017.csv
#>    https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-accident-2017.csv
#> Attempt downloading from: https://data.dft.gov.uk/road-accidents-safety-data/dft-road-casualty-statistics-accident-2017.csv
#> Reading in: 
#> /tmp/Rtmpq2wbe8/dft-road-casualty-statistics-accident-2017.csv
#> Rows: 129982 Columns: 36
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr   (8): accident_index, accident_reference, longitude, latitude, date, lo...
#> dbl  (27): accident_year, location_easting_osgr, location_northing_osgr, pol...
#> 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
#>                       Min.                    1st Qu. 
#> "2017-01-01 00:05:00.0000" "2017-04-03 12:21:15.0000" 
#>                     Median                       Mean 
#> "2017-07-04 20:38:00.0000" "2017-07-04 03:04:59.8841" 
#>                    3rd Qu.                       Max. 
#> "2017-10-04 12:13:45.0000" "2017-12-31 23:31:00.0000" 
# }