Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

int2

convert integers, string to integer vector


Description

Functions for conversion to string representation of integers to arbitrary bases

Usage

NdM( x, B=10 )
  int2ASCII( n)
  int2B( n, B=10, space, plus=lead, lead="",just=c("left","right","center","none") )
  int2Oct( n )
  int2Hex( n )
  strRound( str, digits = getOption("digits"), B=10)

Arguments

str

String representing a real

n

Integer vector

B

1 < integer < 17, base of representation

space

Integer, space for conversion

plus

string for signifying positive values, usually "" or "+"

lead

string for insertion between sign and first significant digit, usually "" or "0"

just

String for choosing kind of justification within 'space', partial matching allowed

x

Vector of reals

digits

no. of digits for roeunding

Details

int2Oct Convert integer to octal representation.
int2Hex Convert integer to hex representation

Value

NdM maximum number of decimal places needed for trunc(x)
int2ASCII,int2B,int2Oct,int2Hex vector of strings represented by 'n'
strRound real, represented by x

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

NdM(10^(1:4)) # 5
  int2ASCII(1:255)[121:129] # "x" "y" "z" "{" "|" "}" "~" "\177" "\200"
  int2B(1:50,2) # all of same length
  int2B(1:50*(-1)^(1:50),just="r") # left flush
  unlist(sapply(1:50,int2B,2,just="l")[1,] ) # individual lengths
  unlist(sapply(1:50,int2B,7)[1,] ) # individual lengths
  unlist(sapply(1:50,int2B)[1,] )
  unlist(sapply(1:50,int2Oct)[1,] )
  unlist(sapply(1:50,int2Hex)[1,] )
  strRound(pi*10^4,0)/10^4 == strRound(pi,4) # TRUE

cwhmisc

Miscellaneous Functions for Math, Plotting, Printing, Statistics, Strings, and Tools

v6.6
GPL (>= 2)
Authors
Christian W. Hoffmann
Initial release
2018-08-24, 10:40:10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.