Convert English letters to numbers or numbers to English letters as on a telephone keypad. When converting letters to numbers, a character vector is returned with "A," "B," or "C" becoming 2, "D," "E", or "F" becoming 3, etc. When converting numbers to letters, a character vector is returned with multiple elements (i.e., "2" becomes a vector of "A," "B," and "C").
phonenumber is an R package that converts English letters to numbers or numbers to English letters as on a telephone keypad.
Author: Steve Myles ([email protected])
Project Home: http://steve.mylesandmyles.info/projects/phonenumber/
License: MIT license
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:
For purposes of this package, the mapping of numbers to letters on a telephone's keypad are as follows:
qzis omitted (or has a value other than 0):
phonenumber is available on CRAN and can be installed accordingly:
You can also install
phonenumber from GitHub using the
The package consists of two functions:
letterToNumber- converts letters in a string to numbers
numberToLetter- converts numbers in a string to letters
Both functions convert non-alphanumeric characters to dash (-) and perform no conversion on their respective base character type (i.e.,
letterToNumber leaves letters as is and
numberToLetter leaves numbers as is).
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:"
string <- "Texas"letterToNumber(string)#>  "83927"
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):
string <- "22"numberToLetter(string)#>  "AA" "AB" "AC" "BA" "BB" "BC" "CA" "CB" "CC"