Recode casualty_type variable from STATS19 data

tc_recode_casualties(x, pattern = NULL, pattern_match = casualties_lookup)

Arguments

x

Character string to recode

pattern

A named character vector with values representing new values. Has the form c("Car long name" = "Car", "Taxi/Private hire car" = "Taxi"). Car long name will be converted into Car in this case.

pattern_match

Character string in the form of c("car" = "car", "bike" = "bike") that replaces all parts of the match.

Examples

(x = stats19::casualties_sample$casualty_type)
#> [1] "Motorcycle 125cc and under rider or passenger"
#> [2] "Pedestrian"                                   
#> [3] "Car occupant"                                 
tc_recode_casualties(x)
#> [1] "Motorcyclist" "Pedestrian"   "Car_occupant"
if (FALSE) {
cas = stats19::get_stats19(2018, "casualties")
cas$casualty_type_simple = tc_recode_casualties(cas$casualty_type)
table(cas$casualty_type)
table(cas$casualty_type_simple)
}