Package 'phonenumber'

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

Help Index


Convert letters to numbers as on a telephone's keypad

Description

Take a character vector and convert it to the equivalent number sequence from a telephone's key pad

Usage

letterToNumber(value, qz = 1)

Arguments

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)

Value

A character vector of numbers and dashes based on value

Examples

# 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 numbers to letters as on a telephone's keypad

Description

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

Usage

numberToLetter(value, decreasing = FALSE, qz = 1)

Arguments

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)

Value

A character vector of letters and dashes based on value

Examples

# 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

Description

phonenumber: Convert letters to numbers and back as on a telephone keypad

phonenumber functions