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)

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"
#> [1] "W11" "X11" "Y11" "Z11"
x <- "911" numberToLetter(x) # also returns "W11" "X11" "Y11" "Z11"
#> [1] "W11" "X11" "Y11" "Z11"
# Convert a number directly numberToLetter(911) # also returns "W11" "X11" "Y11" "Z11"
#> [1] "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-"
#> [1] "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"
#> [1] "000"
numberToLetter("000", qz = 0) # returns "QQQ" "QQZ" "QZQ" "QZZ" "ZQQ" "ZQZ" "ZZQ" "ZZZ"
#> [1] "QQQ" "QQZ" "QZQ" "QZZ" "ZQQ" "ZQZ" "ZZQ" "ZZZ"