keypad_convert: Convert letters or numbers to their keypad counterpart
Description
This function works best when converting numbers to letters, as each number
only has a single possible letter. For each letter, there are 3 or 4 possible
letters, resulting in a number of possible conversions. This function was
intended to convert phonetic telephone numbers to their valid numeric
equivalent; when used in this manner, each letter in a string can be lazily
replaced without changing the rest of the string.
Usage
keypad_convert(x, ext = FALSE)
Arguments
x
A vector of characters or letters.
ext
logical; Should extension text be converted to numbers. Defaults to
FALSE and matches x, ext, and extension followed by a space or number.
Value
If a character vector is supplied, a vector of each elements numeric
counterpart is returned. If a numeric vector (or a completely coercible
character vector) is supplied, then a list is returned, each element of
which contacts a vector of letters for each number.
Details
When replacing letters, this function relies on the feature of
stringr::str_replace_all() to work with named vectors (c("A" = "2")).