Title: | Convert Letters to Numbers and Back as on a Telephone Keypad |
---|---|
Description: | 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"). |
Authors: | Steve Myles [aut, cre] |
Maintainer: | Steve Myles <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.3 |
Built: | 2024-11-13 03:12:28 UTC |
Source: | https://github.com/scumdogsteev/phonenumber |
Take a character vector and convert it to the equivalent number sequence from a telephone's key pad
letterToNumber(value, qz = 1)
letterToNumber(value, qz = 1)
value |
An input value as a character vector with one element (a string) |
qz |
Whether to assign q and z to zero (qz = 0) or not (any other value) |
A character vector of numbers and dashes based on value
# Convert an alphabetic string can be converted directly (with # non-alphanumeric characters replaced by dashes) letterToNumber("R functions") # returns "7-386284667" # Of course, vectors containing strings can also be converted string <- "Phone Number" letterToNumber(string) # returns "74663-686237" # Alphanumeric strings can also be converted with numbers being returned as # is letterToNumber("Jenny's number is 867-5309") # returns "53669-7-686237-47-867-5309" # Specifying qz = 0 maps "q" and "z" to 0 instead of 7 and 9 letterToNumber("qz") # returns "79" letterToNumber("qz", qz = 0) # returns ("00")
# Convert an alphabetic string can be converted directly (with # non-alphanumeric characters replaced by dashes) letterToNumber("R functions") # returns "7-386284667" # Of course, vectors containing strings can also be converted string <- "Phone Number" letterToNumber(string) # returns "74663-686237" # Alphanumeric strings can also be converted with numbers being returned as # is letterToNumber("Jenny's number is 867-5309") # returns "53669-7-686237-47-867-5309" # Specifying qz = 0 maps "q" and "z" to 0 instead of 7 and 9 letterToNumber("qz") # returns "79" letterToNumber("qz", qz = 0) # returns ("00")
Take a character vector (i.e., a telephone number) and convert it to all all possible letter combinations as on from a telephone's key pad
numberToLetter(value, decreasing = FALSE, qz = 1)
numberToLetter(value, decreasing = FALSE, qz = 1)
value |
An input value as a character vector with one element (a string) |
decreasing |
Whether to sort the results in alphabetical order or not |
qz |
Whether to assign q and z to zero (qz = 0) or not (any other value) |
A character vector of letters and dashes based on value
# Convert a string or a vector of numeric characters numberToLetter("911") # returns "W11" "X11" "Y11" "Z11" x <- "911" numberToLetter(x) # also returns "W11" "X11" "Y11" "Z11" # Convert a number directly numberToLetter(911) # also returns "W11" "X11" "Y11" "Z11" # Convert an alphanumeric string (letters are returned as is and # non-alphanumeric characters are returned as dashes) numberToLetter("dial 911!") # returns "DIAL-W11-" "DIAL-X11-" "DIAL-Y11-" "DIAL-Z11-" # Specifying qz = 0 maps "q" and "z" to 0 instead of 7 and 9 numberToLetter("000") # returns "000" numberToLetter("000", qz = 0) # returns "QQQ" "QQZ" "QZQ" "QZZ" "ZQQ" "ZQZ" "ZZQ" "ZZZ"
# Convert a string or a vector of numeric characters numberToLetter("911") # returns "W11" "X11" "Y11" "Z11" x <- "911" numberToLetter(x) # also returns "W11" "X11" "Y11" "Z11" # Convert a number directly numberToLetter(911) # also returns "W11" "X11" "Y11" "Z11" # Convert an alphanumeric string (letters are returned as is and # non-alphanumeric characters are returned as dashes) numberToLetter("dial 911!") # returns "DIAL-W11-" "DIAL-X11-" "DIAL-Y11-" "DIAL-Z11-" # Specifying qz = 0 maps "q" and "z" to 0 instead of 7 and 9 numberToLetter("000") # returns "000" numberToLetter("000", qz = 0) # returns "QQQ" "QQZ" "QZQ" "QZZ" "ZQQ" "ZQZ" "ZZQ" "ZZZ"
phonenumber: Convert letters to numbers and back as on a telephone keypad
letterToNumber
: convert letters to numbers
numberToLetter
: convert numbers to letters