char2num {lazy.tools} | R Documentation |
Convert character vector to numeric vector or vice versa.
char2num(char) num2char(num)
char |
a character vector consisting of strings |
num |
a numeric vector which can be converted to string via raw conversion. |
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 ) )
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)
# 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)