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, the length of the character string need not conform to any standard length telephone number.
When I recently posted some of my Turbo Pascal Stuff, I found an incomplete program that was supposed to do this. I was active on BBSes and, though I don’t recall the reason, I wanted a way to determine the possible words spelled by the BBS phone numbers (and/or how to determine what phone numbers correspond to words/phrases). I never got around to finishing the second part (numbers to letters) in Turbo Pascal, though.
I decided to create this functionality in R for three reasons:
letterToNumber
numberToLetter
For purposes of this package, the mapping of numbers to letters on a telephone’s keypad are as follows:
qz
is omitted (or has a value other than 0):
qz
= 0:
letterToNumber
letterToNumber
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:”
<- "Texas"
string letterToNumber(string)
## [1] "83927"
The function is not limited to letters. Any numeric characters are returned as is and any non-alphanumeric characters (including spaces) are converted to dashes (-):
<- "Texas is #1"
string letterToNumber(string)
## [1] "83927-47--1"
Strings need not be limited to any specific format and all numbers are returned as is:
letterToNumber("Jenny's number is 867-5309")
## [1] "53669-7-686237-47-867-5309"
numberToLetter
numberToLetter
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):
<- "22"
string numberToLetter(string)
## [1] "AA" "AB" "AC" "BA" "BB" "BC" "CA" "CB" "CC"
The function is not limited to numbers. 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:
<- "806!"
string numberToLetter(string)
## [1] "T0M-" "T0N-" "T0O-" "U0M-" "U0N-" "U0O-" "V0M-" "V0N-" "V0O-"