char2num {lazy.tools}R Documentation

Convert character vector to numeric vector or vice versa.

Description

Convert character vector to numeric vector or vice versa.

Usage

char2num(char)

num2char(num)

Arguments

char

a character vector consisting of strings

num

a numeric vector which can be converted to string via raw conversion.

Details

Since these functions can handle double byte characters,
they can be used to store the strings with double byte characters as a list of numeric vectors.

The core part of these functions are:
char to num
num <- as.numeric( charToRaw(char) )
num to char
char <- rawToChar( as.raw( num ) )

Value

char2num
If char is a string ( a vector of length 1 ), num is a vector.
Otherwise, num is a list of length(char)

num2char
If num is a vector, char is a string.
Otherwise, char is a vector of length(num)

Examples

# char is a string
( char <- "This is an example." )
( num <- char2num( char ) )
( is.numeric(num) )
( char2 <- num2char( num ) )

# char is a string vector
( char2 <- c("This is an example.", "2nd line") )
( num2 <- char2num( char2 ) )
( sapply( num2, is.numeric ) )
( char22 <- num2char( num2 ) )

# storing double byte characters in a package: \cr
# See the description of 'generate_zenkaku_sets'.
nn <- c(142,132,146,66,130,205,150,162,230,250,136,234,144,252,129,73)
num2char(nn)


[Package lazy.tools version 0.1.3 Index]