Learn R Programming

cwhmisc (version 6.0)

digits: Test, convert numbers

Description

Test, convert numbers

Usage

allDigits( str ) isNumeric(str) xToBase( x, base=2 )

Arguments

base
Integer
x
Real
str
String

Details

alldigits Convert literally a string to a number. isNumeric Test whether the elements of a character vector represent legal numbers only. str2dig Convert a string to a vector of integers. int integer part truncate towards 0. xToBase return res$a, res$e so that x = a*base^e, abs( a ) in [1, base)

Examples

Run this code
  allDigits(c("1231","89a8742")) #  TRUE FALSE
  isNumeric(c("1231","8.9e-2",".7d2")) # [1]  TRUE  TRUE FALSE
  str2dig("10010") # [1] 1 0 0 1 0
  int(10^(7:10)) # 10000000 100000000 1000000000 NA
  x <- 8.16617
  xToBase(x,2);xToBase(x,3);xToBase(x,4)
 # 8.16617 =  1.02077*2^3 = 2.72206*3^1 = 2.04154*4^1

Run the code above in your browser using DataLab