tc_recode: Recode character strings based on regular expressions

Description Usage Arguments Details Examples

View source: R/tc_recode.R

Description

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.

Usage

1
tc_recode(x, pattern = NULL, pattern_match = NULL)

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.

Details

It is based on the function stringr::str_replace_all().

Examples

1
2
3
4
5
x = c("car long name", "bus", "a bike long", "a bike")
tc_recode(x, pattern = c("car.+" = "car"))
tc_recode(x, pattern = c(".+bike.+" = "bike"))
tc_recode(x, pattern = c("car.+" = "car", ".+bike.+" = "bike"))
tc_recode(x, pattern_match = c("car" = "car", "bike" = "bike"))

saferactive/traffiCalmr documentation built on Nov. 18, 2021, 5:06 a.m.