Learn R Programming

cwhmisc (version 3.0)

numericString: Test string for being a number or made up of digits only, convert to bases.

Description

Functions for testing strings and for conversion of integers to bases other than decimal as string representations.

Usage

numericString(str)
allDigits(str)
intToASCII(i)
intToBase(i,Base=2)
intToOct(i)
intToHex(i)

Arguments

str
A character vector.
i
Integer number to be converted.
Base
Number base to be converted to.

Value

  • TRUE, FALSE, string representations

Details

numericString Test whether the elements of a character vector represent legal numbers only. allDigits Test whether the elements of a character vector consist of digits only. intToASCII Show character or octal representation at a place in the ASCII sequence. intToBase Convert an integer number to string representation in a base between 2 and 16 inclusive. intToOct Convert an integer number to string representation in octal. intToHex Convert an integer number to string representation in hexadecimal.

Examples

Run this code
allDigits(c("1231","89a8742")) #  TRUE FALSE
numericString(c("1231","8.9e-2",".7d2")) # [1]  TRUE  TRUE FALSE
intToASCII(1:255)
sapply(1:50,intToBase,2)
sapply(1:50,intToBase,7)
sapply(1:50,intToOct)
sapply(1:50,intToHex)

Run the code above in your browser using DataLab