This document describes the usage of the two functions in the phonenumber package. Note that, though this package’s functions convert back and forth from numbers to English letters as on a telephone’s keypad. Note that the length of the character string need not conform to any standard length telephone number.
letterToNumbernumberToLetterFor purposes of this package, the mapping of numbers to letters on a telephone’s keypad are as follows:
(I am aware that on some telephones, primarily older models, Q and Z are mapped to 0 rather than to 7 and 9.)
letterToNumberletterToNumber converts a string containing letters into the corresponding numbers on a telephone’s keypad. For example, if the user wants to know what telephone number corresponds to “Texas:”
string <- "Texas"
letterToNumber(string)
## [1] "83927"
The function is not limited to letters, though. Any numeric characters are returned as is and any non-alphanumeric characters (including spaces) are converted to dashes (-) and 1 and 0 are returned as is:
string <- "Texas is #1"
letterToNumber(string)
## [1] "83927-47--1"
numberToLetternumberToLetter converts a string containing numbers into the corresponding letters on a telephone’s keypad. For example, if the user wants to know what possible character strings could be spelled by a sequence of numbers (e.g., 22):
string <- "22"
numberToLetter(string)
## [1] "AA" "AB" "AC" "BA" "BB" "BC" "CA" "CB" "CC"
The function is not limited to numbers, though. Any alphabetic characters are returned as is and any non-alphanumeric characters (including spaces) are converted to dashes (-) and 1 and 0 are returned as is:
string <- "806!"
numberToLetter(string)
## [1] "T0M-" "T0N-" "T0O-" "U0M-" "U0N-" "U0O-" "V0M-" "V0N-" "V0O-"