This function takes messy column names and returns clean ones that work well with R by default. Names that are all lower case with no R-unfriendly characters such as spaces and - are returned.

format_column_names(column_names)

Arguments

column_names

Column names to be cleaned

Value

Column names cleaned.

Examples

# \donttest{ crashes_raw = read_accidents(year = 2017)
#> Reading in:
#> /tmp/RtmpZKiceE/dftRoadSafetyData_Accidents_2017/Acc.csv
#> date and time columns present, creating formatted datetime column
column_names = names(crashes_raw) column_names
#> [1] "accident_index" #> [2] "location_easting_osgr" #> [3] "location_northing_osgr" #> [4] "longitude" #> [5] "latitude" #> [6] "police_force" #> [7] "accident_severity" #> [8] "number_of_vehicles" #> [9] "number_of_casualties" #> [10] "date" #> [11] "day_of_week" #> [12] "time" #> [13] "local_authority_district" #> [14] "local_authority_highway" #> [15] "first_road_class" #> [16] "first_road_number" #> [17] "road_type" #> [18] "speed_limit" #> [19] "junction_detail" #> [20] "junction_control" #> [21] "second_road_class" #> [22] "second_road_number" #> [23] "pedestrian_crossing_human_control" #> [24] "pedestrian_crossing_physical_facilities" #> [25] "light_conditions" #> [26] "weather_conditions" #> [27] "road_surface_conditions" #> [28] "special_conditions_at_site" #> [29] "carriageway_hazards" #> [30] "urban_or_rural_area" #> [31] "did_police_officer_attend_scene_of_accident" #> [32] "lsoa_of_accident_location" #> [33] "datetime"
format_column_names(column_names = column_names)
#> [1] "accident_index" #> [2] "location_easting_osgr" #> [3] "location_northing_osgr" #> [4] "longitude" #> [5] "latitude" #> [6] "police_force" #> [7] "accident_severity" #> [8] "number_of_vehicles" #> [9] "number_of_casualties" #> [10] "date" #> [11] "day_of_week" #> [12] "time" #> [13] "local_authority_district" #> [14] "local_authority_highway" #> [15] "first_road_class" #> [16] "first_road_number" #> [17] "road_type" #> [18] "speed_limit" #> [19] "junction_detail" #> [20] "junction_control" #> [21] "second_road_class" #> [22] "second_road_number" #> [23] "pedestrian_crossing_human_control" #> [24] "pedestrian_crossing_physical_facilities" #> [25] "light_conditions" #> [26] "weather_conditions" #> [27] "road_surface_conditions" #> [28] "special_conditions_at_site" #> [29] "carriageway_hazards" #> [30] "urban_or_rural_area" #> [31] "did_police_officer_attend_scene_of_accident" #> [32] "lsoa_of_accident_location" #> [33] "datetime"
# }