keypad_convert {campfin}R Documentation

Convert letters or numbers to their keypad counterpart


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.


keypad_convert(x, ext = FALSE)



A vector of characters or letters.


logical; Should extension text be converted to numbers. Defaults to FALSE and matches x, ext, and extension followed by a space or number.


When replacing letters, this function relies on the feature of stringr::str_replace_all() to work with named vectors (c("A" = "2")).


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.


keypad_convert("1-800-CASH-NOW ext123")
keypad_convert(c("abc", "123"))

[Package campfin version 1.0.9 Index]