This function takes a character string and recodes it.
Default recoding functions are available in functions such as
tc_recode_vehicle_type()
and tc_recode_casualties
.
tc_recode(x, pattern = NULL, pattern_match = NULL)
x | Character string to recode |
---|---|
pattern | A named character vector with values representing new values.
Has the form |
pattern_match | Character string in the form of
|
It is based on the function stringr::str_replace_all()
.
x = c("car long name", "bus", "a bike long", "a bike") tc_recode(x, pattern = c("car.+" = "car")) #> [1] "car" "bus" "a bike long" "a bike" tc_recode(x, pattern = c(".+bike.+" = "bike")) #> [1] "car long name" "bus" "bike" "a bike" tc_recode(x, pattern = c("car.+" = "car", ".+bike.+" = "bike")) #> [1] "car" "bus" "bike" "a bike" tc_recode(x, pattern_match = c("car" = "car", "bike" = "bike")) #> [1] "car" "bus" "bike" "bike"